Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (Dico), 16,767 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
why is the copy-pasted working code crashing? #205388
05/06/08 11:14
05/06/08 11:14
Joined: Jul 2007
Posts: 24
N
noobie86 Offline OP
Newbie
noobie86  Offline OP
Newbie
N

Joined: Jul 2007
Posts: 24
Hi i'm programming a match-3 game using Lite-C and i have the following inexplicable problem: here's the part of the code that's causing the crash i don't understand:

 Code:
//row number 4, n=22 to n=28
while(n>21 && n<=28)
{
wait(1);                     // give a small delay before creation
randomize(); c = random(3);  //random number for creation, 'c' is an int
create_ball = c;
	
if(c==0){balls[n] = ent_create("gem_r.mdl",vector((n-21)*40,0,0),rotate_me);}
if(c==1){balls[n] = ent_create("gem_g.mdl",vector((n-21)*40,0,0),rotate_me);}
if(c==2){balls[n] = ent_create("gem_b.mdl",vector((n-21)*40,0,0),rotate_me);}
if(c==3){balls[n] = ent_create("gem_w.mdl",vector((n-21)*40,0,0),rotate_me);}
		
me = balls[n];       //declare a pointer to the created ball
my.skill11 = c;      //defines the 'type' so that match-3 can be checked
my.tilt=90;          //only because it looks better this way :)
balls[n][1] = my.x;  //store the co-ordinates in arrays to be accessed later
balls[n][2] = my.y;
n+=1;                //keep incrementing 'n'
wait(1);
}

//row number 5, n=29 to n=35
while(n>28 && n<=35)
{
wait(1);
randomize(); c = random(3);
create_ball = c;
	
if(c==0){balls[n] = ent_create("gem_r.mdl",vector((n-28)*40,-40,0),rotate_me);}
if(c==1){balls[n] = ent_create("gem_g.mdl",vector((n-28)*40,-40,0),rotate_me);}
if(c==2){balls[n] = ent_create("gem_b.mdl",vector((n-28)*40,-40,0),rotate_me);}
if(c==3){balls[n] = ent_create("gem_w.mdl",vector((n-28)*40,-40,0),rotate_me);}
		
me = balls[n];
my.skill11 = c;
my.tilt=90;
balls[n][1] = my.x;
balls[n][2] = my.y;
n+=1;
wait(1);
}


here 'n' is indicative of the row number. i have 7 rows. Whenever 'n' reaches 'n+7', it moves to the next row. I copy-pasted the code 7 times so that 7 rows are created. All the rows create the 'gems' and work fine except for the 5th, which causes a 'Crash in (function name)'. If the 5th row creation code is deleted, it works fine and creates the gems in rows 6 and 7. And here's the funny part: if the 5th row code is included, it creates gems until n reaches '33' and then crashes i.e. it creates 4 gems in the 5th row before crashing.

Since i've copy-pasted the code, there shouldn't be a syntax error. I've gone through the code many many times and just can't find the problem. What might be going wrong?

By the way, thanks to Quadraxas for refering me to Lite-C. Its made the programming of this game a lot easier (except for 'Crash in Main' and 'Crash in (function name)) \:\)

Re: different behavior at different times?? [Re: noobie86] #205390
05/06/08 11:39
05/06/08 11:39
Joined: Jul 2007
Posts: 24
N
noobie86 Offline OP
Newbie
noobie86  Offline OP
Newbie
N

Joined: Jul 2007
Posts: 24
Hi again \:\) i found the cause of the crash but still no idea how to solve it:

the crash happens when n=32 and i try to store

balls[32][1] = my.x;

however "balls[32][2] = my.y" works fine.??? how is that possible?

also when i try to include paths (again copy-pasted format from the help file) it says PATH undeclared identifier..?

Last edited by noobie86; 05/06/08 12:40.
Re: different behavior at different times?? [Re: noobie86] #205401
05/06/08 13:11
05/06/08 13:11
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline
Serious User
Happy Birthday Scorpion  Offline
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
the first thing is, that you sometimes just use 1 index and sometimes 2...
 Code:
balls[n] =....

balls[n][1] =....


I think you should use 0 and 1 as indices and not 1 and 2...

 Code:
balls[n][1] = my.x;
balls[n][2] = my.y;
>>>>>>
balls[n][0] = my.x;
balls[n][1] = my.y;


Re: different behavior at different times?? [Re: noobie86] #205467
05/06/08 18:43
05/06/08 18:43
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
 Originally Posted By: noobie86
also when i try to include paths (again copy-pasted format from the help file) it says PATH undeclared identifier..?

PATH is wdl syntax and has nothing to do with lite-c. If you want to include paths then use either the #pragma_path command or create a .wdl file with the same name as you main script and write you path statements into this .wdl file.


Always learn from history, to be sure you make the same mistakes again...

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1