Jump to content


Rugos

Member Since 09 Jul 2009
Offline Last Active Apr 20 2013 09:20 PM

Topics I've Started

String Related Array Indexes (Solved)

14 April 2013 - 06:05 AM

EDIT: for some reason, the GMC's code thingy made the text all green. Weird.

 

Hey gang! Hope I'm posting in the right forum :)

 

I recently started working on a pokemon simulator. While this may mean nothing to you, here is my dilemna: 

 

turn=1

i=0
repeat(2)
{
    i+=1
    f='C:\Users\Cheshire\Desktop\'+get_string('Team '+string(i)+' file location?','basic')+'.txt'
    ff=file_text_open_read(f)
    t=file_text_read_string(ff)
    file_text_close(ff)
    t=string_replace_all(t,'team[','team['+string(i)+',')
    
    j=0
    repeat(6)
    {
        j+=1
        l=0
        repeat(4)
        {
            l+=1
            move[j,l]=''
        }
    }
    
    j=0
    repeat(6)
    {
        j+=1
        l=0
        repeat(4)
        {
            l+=1
            t=string_replace(t,'move['+string(j)+','+string(l)+']','move['+string(i)+',move['+string(j)+','+string(l)+']]')
        }
    }
    execute_string(t)
    get_string(t,'')
}

dialogue=''
command=''
ncommand=0

 

This is meant to open up two different files (for the two different teams, I didn't want to just copy+paste the code and change some minor variables), and edit some of the text within, then execute it. Because the team files are formatted for individual teams, they use arrays that don't differentiate between team 1 and team 2, see below sample team file.


team[1]='Squirtle' team[2]='Charmander' team[3]='Bulbasaur' team[4]='' team[5]='' team[6]='' move[1,1]='Tail Whip' move[1,2]='Bubble' move[1,3]='Withdraw' move[1,4]='Scratch' move[2,1]='Scratch' move[2,2]='Growl' move[2,3]='Ember' move[2,4]='Smokescreen' move[3,1]='Tackle' move[3,2]='Growl' move[3,3]='Vine Whip' move[3,4]='Leach Seed' move[4,1]='' move[4,2]='' move[4,3]='' move[4,4]='' move[5,1]='' move[5,2]='' move[5,3]='' move[5,4]='' move[6,1]='' move[6,2]='' move[6,3]='' move[6,4]='' 

 

 

 

The error I'm getting is this:


Error in code at line 1:
   team[1,1]='Squirtle' team[1,2]='Charmander' team[1,3]='Bulbasaur' team[1,4]='' team[1,5]='' team[1,6]='' move[1,move[1,1]]='Tail Whip' move[1,move[1,2]]='Bubble' move[1,move[1,3]]='Withdraw' move[1,move[1,4]]='Scratch' move[1,move[2,1]]='Scratch' move[1,move[2,2]]='Growl' move[1,move[2,3]]='Ember' move[1,move[2,4]]='Smokescreen' move[1,move[3,1]]='Tackle' move[1,move[3,2]]='Growl' move[1,move[3,3]]='Vine Whip' move[1,move[3,4]]='Leach Seed' move[1,move[4,1]]='' move[1,move[4,2]]='' move[1,move[4,3]]='' move[1,move[4,4]]='' move[1,move[5,1]]='' move[1,move[5,2]]='' move[1,move[5,3]]='' move[1,move[5,4]]='' move[1,move[6,1]]='' move[1,move[6,2]]='' move[1,move[6,3]]='' move[1,move[6,4]]='' 
                                                                                                                  ^
at position 113: Wrong type of array index

 

 

As you can see, all the correct code is getting replaced (this is the first team, the first iteration of i, and hence it's move[team,[move[pokemon,movename]] ), and it's ready to run, but I get the error :/

 

What am I doing wrong? I feel like it's something obvious.

 

I know I could be using for()s, but I prefer using repeat()s.


Game Only Works 1/5 Times When Started.

12 April 2013 - 11:50 PM

This is really unnerving me. The game works fine, and the code works to (as evidenced by debugging variable observer), but about 4/5 times when the game is run the game won't draw the text. Have I stumbled on some obscure bug? Am I being obscenely stupid? Download here: https://www.dropbox....cary Times.gm81

 

If you're to lazy, the code in the step event is:

if keyboard_check_pressed(vk_anykey) && !keyboard_check_pressed(vk_enter) && !keyboard_check_pressed(vk_backspace)
{
    code+=keyboard_lastchar
}

if keyboard_check_pressed(vk_backspace)
{
    code=string_delete(code,string_length(code),1)
}

if keyboard_check_pressed(vk_enter)
{
    code=''
}

 

And the code in the create is to declare code, and in the draw to draw string code at 0,0. I don't have any other settings in the game touched, nothing weird at all.


Dungeon Generator Branches Running Side By Side

17 March 2013 - 06:05 PM

Hi everyone!

I've been fiddling around with a dungeon generator for the last couple of days, and went through several different iterations before it eventually came to this:

for(cx=0;cx<50;cx+=1)
{
        for(cy=0;cy<50;cy+=1)
        {
                cell[cx,cy]=0       
        }
}

sx=round(random(10)+20)
sy=round(random(10)+20)

cell[sx,sy]=2

ccx=sx
ccy=sy+1

i=0
d=1
repeat(round(random(10))+3)
{
        if i=1
        {
                if d=1
                {
                        d=2
                }
                else
                {
                        d=1
                }
        }
        
        n=choose(1,-1)
        i=1
        
        repeat(round(random(5))+1)
        {
                cell[ccx,ccy]=1
                if d=1
                {
                        if ccx+n>2
                        {
                                ccx+=n
                        }
                }
                else
                {
                        if ccy+n>2
                        {
                                ccy+=n
                        }
                }
        }
        
        sccx=ccx
        sccy=ccy
        if d=1
        {
                d=2
        }
        else
        {
                d=1
        }
        n=choose(1,-1)
        
        repeat(round(random(5))+1)
        {
                if cell[ccx,ccy]=0
                {
                        cell[ccx,ccy]=1
                        if d=1
                        {
                                if ccx+n>2
                                {
                                        ccx+=n
                                }
                        }
                        else
                        {
                                if ccy+n>2
                                {
                                        ccy+=n
                                }
                        }
                }
                else
                {
                        break
                }  
        }
        
        if d=2
        {
                d=1
        }
        else
        {
                d=2
        }
        ccx=sccx
        ccy=sccy
}


if cell[ccx,ccy]=0
{
        cell[ccx,ccy]=3
}
else
{
        if cell[ccx,ccy+1]=0
        {
                cell[ccx,ccy+1]=3
        }
        else
        {
                if cell[ccx,ccy-1]=0
                {
                        cell[ccx,ccy-1]=3
                }
                else
                {
                        if cell[ccx+1,ccy]=0
                        {
                                cell[ccx+1,ccy]=3
                        }
                        else
                        {
                                if cell[ccx-1,ccy]=0
                                {
                                        cell[ccx-1,ccy]=3
                                }
                        }
                }
        }
}

It creates a starting point, sx and sy, and fills the grid at that point as 2. Then it creates hallways, filling the grid with occupied spaces (1s), then creates and exit (3). To make it more difficult to get through for the player, who won't be able to see the overall picture but will have to choose between forks, at every branch in the initial halls another hall leading to a dead end is created, so that the player will most likely take at least one wrong turn before getting to the end.
The problem is that occasionally the branches run side by side, and create a path with a width of two instead of one (which looks ugly). I can't really think of an easy way to get rid of this... thoughts?
Also, the end part is horribly inefficient... don't judge me :(/>/>/>

Also, if I didn't explain myself clearly, you can put
for(i=0;i<50;i+=1)
{
        for(j=0;j<50;j+=1)
        {
                if cell[i,j]=1
                {
                        draw_sprite(spr_test,0,i*16,j*16)
                }
                if cell[i,j]=2
                {
                        draw_sprite(spr_test,1,i*16,j*16)
                }
                if cell[i,j]=3
                {
                        draw_sprite(spr_test,2,i*16,j*16)
                }  
        }
}

In the draw event of an object, the first code in the create event, a game restart in the space (or whatever) and see my problem firsthand.

Thanks.

If this isn't advanced, sorry, and feel free to move it to novice & intermediate.

Undeclared Array Variable

15 March 2013 - 03:18 PM

mx=round(random(30))
my=round(random(30))
for(cx=0;cx<mx;cx+=1)
{
        for(cy=0;cy<mx;cy+=1)
        {
                cell[cx,cy]=0       
        }
}
sx=choose(999,round(random(mx-1))+1)
if sx=999
{
        sy=round(random(my))
        sx=1
}
else
{
        sy=1
}
ex=sy
ey=sx
ccellx=sx
ccelly=sy

cell[sx,sy]=2
cell[ex,ey]=3

i=0
while(i!=1)
{
        rx=round(random(2))
        ry=round(random(2))
        if ccellx+1-rx>0 && ccellx+1-rx<=mx && ccelly+1-ry>0 && ccelly+1-ry<=my
        {
                if cell[ccellx+1-rx,ccelly+1-ry]=0
                {
                        cell[ccellx+1-rx,ccelly+1-ry]=1
                        ccellx=ccellx+1-rx
                        ccelly=ccelly+1-ry
                }
                if cell[ccellx+1-rx,ccelly+1-ry]=3
                {
                        i=1
                }
        }
}


Throws up the error array index out of bounds. I check to make sure it IS within bounds with
if ccellx+1-rx>0 && ccellx+1-rx<=mx && ccelly+1-ry>0 && ccelly+1-ry<=my

What am I doing wrong?

Choose Executing All Arguments

09 March 2013 - 10:04 AM

ilvl=round(random(24))+1

type=choose('Common','Superior','Magical')//,'Legendary')
slot=choose('Main Hand','Off Hand','Boots','Chest','Helm','Ring','Amulet')
affixes=''
name=''

if type='Common'
{
        name+=choose('Mundane','Banal','Prosaic')+' '
        scr_get_item_name()
        scr_add_affix_hard(1)
}
if type='Superior'
{
        name+=choose('',choose('Masterful','Wrought','Etched')+' ')
        scr_get_item_name()
        scr_add_affix_hard(2)
        if round(random(2))=0
        {
                scr_add_affix_socket()
        }
        else
        {
               scr_add_affix_stats() 
        }
        name+=' '+choose('',choose('of Kings','of Heroes','of the Stars'))
}
if type='Magical'
{
        name+=choose('',choose('Enigmatic','Mysterious','Powerful')+' ')
        scr_get_item_name()
        scr_add_affix_hard(2)
        repeat(1)
        {
               if slot='Main Hand' 
               {
               choose(scr_add_affix_offence(),scr_add_affix_stats(),scr_add_affix_socket())
               }
               if slot!='Main Hand' 
               {
               choose(scr_add_affix_defense(),scr_add_affix_misc(),scr_add_affix_stats(),scr_add_affix_socket())
               }
        }
        name+=' '+choose('',choose('of Valor','of Prophecy','of the Omens'))
}

choose(scr_add_affix_offence(),scr_add_affix_stats(),scr_add_affix_socket()) and choose(scr_add_affix_defense(),scr_add_affix_misc(),scr_add_affix_stats(),scr_add_affix_socket()) are executing all the scripts instead of just one. How do I fix?