Scripting If statements with GUI button interaction

Started by artbypostman, Sat 12/12/2009 07:12:24

Previous topic - Next topic

artbypostman

I am working on a game for my class Art for games.  And this is my first try at scripting and the video tutorials were a GREAT help!  In fact I hope more come along. 
But I have become stuck on execution of one idea.
I tried going through the tutorials and what not but I couldnt find help

So as the game is played you have options to choose through GUI buttons.
Now I have set up a Game over room for the wrong answer. 
I have no problem with the changing of rooms to the game over room.
But I wanted to use a "display" thread stating what happened to get the game over due to your decision.
So I tried using this;

function altercation_OnClick(GUIControl *control, MouseButton button)
{
  gBlackdog.Visible = false;
  Wait (10);
  cHawkins.ChangeRoom (6, 1222, 1648);
  Display (" Black Dog runs Captain Billy Bones through with his blade and runs out of the Admiral Benbow off down the road.  Your journey never had a chance to even start.  With the death of your father you end up working the rest of your life at the Admiral Benbow.");

the problem as you can imagine is the display text happens before the change room.

So I  figured I had to create an If statement inside of the Game Over room for each button that will take you there.
How would I go about scripting the if statement for the click of a gui button so when it changes to the Game Over screen  It displays the text I want?  Because I will be using this screen throughout the whole game I dont want to just use a Display command as you enter the room cause the display will be different depending on which path the player takes to get there.
 
       

Gilbert

It's by design that ChangeRoom() MUST be the last function to be executed, as after the room is changed the original room script is unloaded and you couldn't execute any other stuff afterwards.
The solution is to put that display line in the next room (possibly in "enters room" event). To make sure that the displayed line would only be displayed once for the time after that button is clicked you may use a global variable to track it.

So, you may define a global variable (from the global variable pane in the editor, probably) called, say, blah and set its initial value to 0.

Then in the original room, the script for the click could be:
Code: ags

  gBlackdog.Visible = false;
  Wait (10);
  blah=1;
  cHawkins.ChangeRoom (6, 1222, 1648);


And in the "enters room" event in the next room:
Code: ags

  if (blah == 1){
    Display (" Black Dog runs Captain Billy Bones through with his blade and runs out of the Admiral Benbow off down the road.  Your journey never had a chance to even start.  With the death of your father you end up working the rest of your life at the Admiral Benbow.");
    blah = 0; //so that it won't be displayed again the next time.
  }

artbypostman

Thanks!  I dont know why I didnt think of that.  I for some reason was thinking I had to use the if to state that if the button was pushed. >.< the global variable makes total sense.  I appreciate it

artbypostman

So I tried and Im still having problems.  When I enter the room it still wont display the text I want it to. 
I created the Global Var.  Failure as an int and set it to 0

Button Script:
function altercation_OnClick(GUIControl *control, MouseButton button)
{
  gBlackdog.Visible = false;
  Wait (10);
  Failure=1;
  cHawkins.ChangeRoom (6, 1222, 1648); 
}


Then my room script:

function room_AfterFadeIn(){
if (Failure == 1) { 
  Display (" Black Dog runs Captain Billy Bones through with his blade and runs out of the Admiral Benbow off down the road.  Your journey never had a chance to even start.  With the death of your father you end up working the rest of your life at the Admiral Benbow.");
  Failure=0;
}
}

Its not displaying anything.  I even tried to make it a textural overlay but still nothing appears on the screen.

Gilbert

I'm not quite sure about the problem. To check, put a Display() before the 'if (Failure==1)' to see whether the AfterFadeIn() function is correctly linked to the event and get called at appropriate time, like:
Code: ags

function room_AfterFadeIn(){
  Display("blah");
  if (Failure == 1) {  
    Display (" Black Dog runs Captain Billy Bones through with his blade and runs out of the Admiral Benbow off down the road.  Your journey never had a chance to even start.  With the death of your father you end up working the rest of your life at the Admiral Benbow.");
    Failure=0;
  }
}


If that still doesn't show where the problem is, you may upload the game files and let us see if we can find the problem.

SMF spam blocked by CleanTalk