The Dink Network

Reply to Re: Scripting problem

If you don't have an account, just leave the password field blank.
Username:
Password:
Subject:
Antispam: Enter Dink Smallwood's last name (surname) below.
Formatting: :) :( ;( :P ;) :D >( : :s :O evil cat blood
Bold font Italic font hyperlink Code tags
Message:
 
 
October 3rd 2010, 09:56 AM
slimeg.gif
metatarasal
Bard He/Him Netherlands
I object 
The problem is that variables declared in the void main() procedure of a script do not exist in custom procedures. According to the custom procedure you are running &x doesn't exist, that's why you are getting the x with a line under it. You can use this to make it work:

void main (void)
{
	int &x;
	int &y;
	&x = 100;
	&y = 100;
	int &junk;
	int &dir1;
	sp_speed(&current_sprite, 5);
	sp_brain(&current_sprite, 0);
	sp_x(&current_sprite, &x);
	sp_y(&current_sprite, &y);
	sp_hard(&current_sprite, 0);
	draw_hard_map();
}
void push(void)
{
	freeze(1);	
	sp_hard(&current_sprite, 1);
	draw_hard_map();
	
	&dir1 = sp_dir(1, -1);
	
	if(&dir1 == 6)
	{
		&x = sp_x(&current_sprite, -1);
		&x += 20;
		move_stop(&current_sprite, 6, &x, 1);
	}
	if(&dir1 == 2)
	{
		&y = sp_y(&current_sprite, -1);
		&y += 20;
		move_stop(&current_sprite, 2, &y, 1);
		
	}
	if(&dir1 == 8)
	{
		&y = sp_y(&current_sprite, -1);
		&y -= 20;
		move_stop(&current_sprite, 8, &y, 1);
		
	}
	if(&dir1 == 4)
	{
		&x = sp_x(&current_sprite, -1);
		&x -= 20;
		move_stop(&current_sprite, 4, &x, 1);
	}
	say("&dir", 1);
	sp_hard(&current_sprite, 0);
	unfreeze(1);
	check_p();
}
void talk(void)
{
	say("It's a stone", 1);
}
void check_p(void)
{
	int &x = sp_x(&current_sprite, -1);
	int &y = sp_y(&current_sprite, -1);
	
	if (&x >= 221)
	{
		if (&x <= 272)
		{
			if (&y <= 304)
			{
				if (&y >= 268)
				{
                                        //I need to print the x and y
                                        //to figure out why the script never gets here
					say("It's inside!", 1);
					goto skip;
				}
			}
			
		}
		
	}
	say("&x", 1);
        //Now it does work! Yay!
skip:
	draw_hard_map();
}


I agree that this is a really strange bug, I've had to make scripts 3 times as long in the past because of this. Variables do retain their value from void main() to other standard procedures, but apparently custom procedures work differently. Highly annoying.

Also I'm not exactly sure if a variable used in a custom procedure is cleaned up after running the procedure, I sure hope so as this is wasting variables...