[SOLVED] Script doesn't appear to run (The Sequel!): Repeatedly Execute

Started by HammerBlade, Tue 11/12/2007 03:40:34

Previous topic - Next topic

HammerBlade

SOLUTION:  It turns out that all I had to do was declare the variables from the global script, then "export" those variables, and then call them in the room they belonged in using "import." 

(Start Intro--Skip to 'End Intro' to get to meaningful part of post.)

For anybody who read my previous thread about scripts not seeming to run, you'll recall I have begun a card game project and have used objects instead of GUI buttons for the games interface.  This has come back to bite me in the butt, for I've run out of objects to use and finally have resorted to employing GUI's in my design.  Of course, since object scripts run locally and GUI's run globally, the need for a workaround has arisen.  Being my stubborn self, I'm still refusing to start over, because (a) I'm not interested in rewriting 600+ lines of code just yet, and (b) it'd be better in the long-run to know why this snag has come up anyway.

(End Intro--The Problem)   
(Or for Phoenix Wright fans: --WITNESS TESTIMONY--)

The following are a list of facts about the script of my game:

1) The Script Header contains the line "bool workaround_strike = false;".

2)  In a room of the game (room 2), there is an "if" statement within the content of the function which handles the "repeatedly execute" event.  In particular, this statement tests whether workaround_strike = true.  If it is true, then the stuff inside of it happens.

Code: ags
<
	if (workaround_strike == true)  
	{
	  if (turn == 1)  //If P1 attacked P2 with a card...
	  {
				p1.attacking = true;
				blocking(2);  //P2 Must now choose a card to block
											//with (or not)
		}
		
		if (turn == 2)  //If P2 attacked P1 with a card...
		{
				p2.attacking = true;
				blocking(1);  //P1 must now choose a card to block 
		}                 //with (or not)
		Display("before workaround is equal to false");
		workaround_strike = false;
		Display("after workaround is equal to false");
		
	}
>


3)  A GUI button is set to, whenever it is clicked on, to set workaround_strike
to a value of "true".

Code: ags
<
		if (interface == gStrike.ID)  {
			val_display = String.Format("workaround_strike is equal to %d", workaround_strike);
			Display (val_display);
			workaround_strike = true;
			val_display = String.Format("workaround_strike is equal to %d", workaround_strike);
			Display (val_display);
		}
>

(Note:  val_display is a String variable, declared at the beginning of the global script.)

So then, if I click on the GUI button, the "if" statement within the "repeatedly
execute" event of room 2 should run its script, right?

"Not quite" is the answer I've been getting so far.

Trouble-shooting methods I've already tried:

-Placing a Display() function before and after the workaround_strike = true assignment in the GUI script.  Both ran, and both gave different values, thus
indicating that the assignment worked fine.

-Placing Display() functions at the beginning and end of the "if" statement within the "repeatedly execute" event.  Neither of these messages showed up, thus indicating that the "if" statement wasn't tested (or possibly Repeatedly_execute was still false for some reason.)

Any ideas as to why "repeatedly execute" doesn't seem to catch the boolean switch?  Any and all input will be greatly appreciated!

--End Post--  (Or, to PW Fans: --CROSS EXAMINATION--)

Khris

Move the "bool workaround_strike = false;" line to the start of the global script, put "export workaround_strike;" beneath it, then add "import bool workaround_strike;" to the script header.

Defining a variable in the header will create several of these variables, one for the global script and one for each room script. All of them have their own value as they are in fact several different variables, so you kept changing one of them, then testing another one.

(I didn't read your whole post, just until 1), but I'm pretty sure that's the problem.)

HammerBlade

I was afraid that the header had created multiple variables...but it's good to have conformation. :-\

The bad news is that importing the bool to the header file didn't seem to change anything...

The good news is that, after then trying to import said variables to room 2, the function worked!  MUCH thanks for the info on importing/exporting variables from the global script to individual room scripts. 

Khris

I'm just curious, how (why) did you import the variable to the second room?

A global variable is supposed to be declared and exported in the global script, then imported in the script header. That way it can automatically be accessed and changed from every room script, too.

Following my steps should have solved the problem, without the need to add further import lines anywhere.

SMF spam blocked by CleanTalk