User Tag List

Results 1 to 4 of 4

Thread: Varible Problems..

  1. #1
    Octorok
    Join Date
    May 2007
    Posts
    331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,506
    Level
    13
    vBActivity - Bars
    Lv. Percent
    11.29%

    Varible Problems..

    I've been wracking my brain all day trying to figure out what is wrong with this code, I'm stumped so lets see if anyone else can tell me what i am doing wrong.

    It compiles fine, but it does nothing, i put in a Trace(); to test the results of the varible but all i get is 0's

    Code:
    ffc script pathTest{
    void run(int this_ffc_num)
    {
    
    while (true){
    //declare vars
    int best_dir = 0;
    
    	// "this_ffc->" bug workaround
    	ffc this_ffc = Screen->LoadFFC(this_ffc_num);	
    	int rnum = Floor(Rand(4)+1);
    	if (rnum==1) { best_dir = 1; }
    	if (rnum==2) { best_dir = 2; }
    	if (rnum==3) { best_dir = 3; }
    	if (rnum==4) { best_dir = 4; }	
    	//routine to move FFC in chosen direction	
    	Trace(best_dir);
    	if (best_dir==1)
    	{
    		for (int n=1 ; n<16 ; n+=4)
    		{
    		this_ffc->Y-=4;
    		Waitframe();
    		}
    	}	
    	if (best_dir==2)
    	{
    		for (int n=1 ; n<16 ; n+=4)
    		{
    		this_ffc->X-=4;
    		Waitframe();
    		}
    	}
    	if (best_dir==3)
    	{
    		for (int n=1 ; n<16 ; n+=4)
    		{
    		this_ffc->Y+=4;
    		Waitframe();
    		}
    	}
    	if (best_dir==4)
    	{
    		for (int n=1 ; n<16 ; n+=4)
    		{
    		this_ffc->X+=4;
    		Waitframe();
    		}
    	}
    
    
    	Waitframe();
    }//ends while true
    }//ends void run
    }//ends pathTest
    This is not my original script, but a simplified version, still the problem remains the same. it SHOULD move the FFC one grid space in a random direction every 4 tics

    EDIT: okay i figured out the Rand problem (i forgrot to floor it) but now it looks like that was not the problem in the original script, (i did not use a random number) so mabye i can figure it out now...

    Also, this time when i ran a Trace(rnum); i thought it would have given me the output of the random number but it just gave me a bunch of Zasm (which i only partialy understand) how can i just get the output of a var??

  2. #2
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.52%

    Re: Varible Problems..

    Sure enough, you've found a bug: Rand() currently returns a float, instead of an integer as documented. Fixed in the next build.

  3. #3
    Octorok Dan Furst's Avatar
    Join Date
    Oct 2005
    Age
    39
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,501
    Level
    13
    vBActivity - Bars
    Lv. Percent
    9.63%

    Re: Varible Problems..

    Yeah, Rand() is defined as int but returns a float. Good catch.

    Here is a cleaned-up version that does what you want. Note that the ffc will probably fly off the screen, since there is no bounds checking. Don't forget to pass in the ffc number with D0.

    Code:
    import "std.zh"
    ffc script pathTest{
    void run(int this_ffc_num)
    {
    	// "this_ffc->" bug workaround
    	ffc this_ffc = Screen->LoadFFC(this_ffc_num);
    
    	while(true)
    	{
    		int best_dir = Floor(Rand(4))+1;
    		//routine to move FFC in chosen direction	
    		if(best_dir==1)
    		{
    			for(int n=0 ; n<4 ; n++)
    			{
    				this_ffc->Y-=4;
    				Waitframe();
    			}
    		}	
    		else if(best_dir==2)
    		{
    			for(int n=0 ; n<4 ; n++)
    			{
    				this_ffc->X-=4;
    				Waitframe();
    			}
    		}
    		else if(best_dir==3)
    		{
    			for(int n=0 ; n<4 ; n++)
    			{
    				this_ffc->Y+=4;
    				Waitframe();
    			}
    		}
    		else if(best_dir==4)
    		{
    			for(int n=0 ; n<4 ; n++)
    			{
    				this_ffc->X+=4;
    				Waitframe();
    			}
    		}
    		else
    		{
    			Waitframe();
    		}
    	}//ends while true
    }//ends void run
    }//ends pathTest
    If you don't want it to fly off the screen, I would suggest adding some ifs like so:

    Code:
    for(int n=0 ; n<4 ; n++)
    {
    	if(this_ffc->Y < 4)
    	{
    		this_ffc->Y+=4;
    	}
    	else
    	{
    		this_ffc->Y-=4;
    	}
    	Waitframe();
    }

  4. #4
    Octorok
    Join Date
    May 2007
    Posts
    331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,506
    Level
    13
    vBActivity - Bars
    Lv. Percent
    11.29%

    Re: Varible Problems..

    Thank you DarkDragon and Dan Furst,
    as i said this is a simplified version,
    i already have walkabilty checking and decision makeing in place, just a few tweaks now and Zelda Classic will have a working A* Pathfinding script :)

    as soon as it is working perfectly I will post it in Script Showcase

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social