Game authors and players, please read this thread!

Author Topic: how to cancel a running timer? [SOLVED]  (Read 636 times)  Share 

how to cancel a running timer? [SOLVED]
« on: 25 Jul 2012, 08:40 »
I have the following problem:
I would like the player to press the bell of a house. After about 5 seconds a which opens the door and enchants the player. Only if the player hides behind a flowerpot the which will not find him. For this I have set up the following:
Code: Adventure Game Studio
  1. function hDoorbell_Interact()
  2. {
  3. cBellatrix.LockViewFrame(3, 2, 1);
  4. Wait(80);
  5. cBellatrix.UnlockView();
  6. SetTimer(1, 220);
  7. isBell = true;
  8.   if  ( false && BellaHidden == false && IsTimerExpired(1)) {
  9. Death Scene occurs
  10. }
  11. }
  12.  
Code: Adventure Game Studio
  1. function room_RepExec()
  2. {
  3. if (IsTimerExpired(1)){
  4. Death Scene occurs
  5. }
  6. }
  7.  
But if the player does click on the big flower pot just in time then the player hides and the following appears:
Code: Adventure Game Studio
  1. function hTopf_Interact()
  2. {
  3. if (isBell == false){
  4. cBellatrix.Walk(195, 484, eBlock, eWalkableAreas);
  5. cBellatrix.Say("There is a big Flowerpot.");
  6. }
  7. else if (isBell == true){
  8. cBellatrix.Walk(98, 508, eBlock, eWalkableAreas);
  9. cBellatrix.LockViewFrame(3, 2, 0);
  10. Wait(90);
  11. Death Scene occurs
  12. isBell = false;
  13.   }
  14. }
  15.  
« Last Edit: 27 Jul 2012, 22:08 by Caracal »

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: how to cancel a running timer?
« Reply #1 on: 25 Jul 2012, 11:13 »
You can't really do it that way.

First of all, in hDoorbell_Interact Bellatrix doesn't walk to the hotspot first, while in hTopf_Interact she does. Not sure how your game is set up, but one of those must be wrong, right?
Now, further down in hDoorbell_Interact you're testing a condition. That won't work in the way you think because this condition is tested exactly once, and it's tested immediately after you've started the timer. So disregarding the false, the condition won't ever be fulfilled anyway.

What you need to do:
-Interacting with the doorbell starts a timer and sets a variable (isBell) to true, IF isBell is false. Otherwise we get "I just pressed the doorbell."
-Interacting with the flower pot: IF isBell: hide, else look at it
-rep_ex: if TimerExpired
                   if (hidden) stuff happens
                   else death scene happens

Also, and I can't stress this enough: INDENTATION!
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Re: how to cancel a running timer?
« Reply #2 on: 26 Jul 2012, 20:55 »

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: how to cancel a running timer?
« Reply #3 on: 27 Jul 2012, 00:55 »
You can always use your own timer. Just set a room variable, decrease it in room_RepExec and check its value. Assuming the event is triggered as soon as the variable reaches 0, to turn off the timer, set it to -1.
A better way of course is to set it to 1 when Bella hides behind the pot, so the cutscene is started in the next game loop.
Code: Adventure Game Studio
  1. // room script
  2. int doorbell_timer = -1;
  3.  
  4. // instead of SetTimer
  5.   doorbell_timer = 220;
  6.  
  7. // in room_RepExec
  8.   if (doorbell_timer > 0) doorbell_timer--;
  9.   if (doorbell_timer == 0) {
  10.     ...
  11.   }

Btw, you didn't have the entire cutscene code twice in your room script, did you?
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Re: how to cancel a running timer?
« Reply #4 on: 27 Jul 2012, 22:05 »
Well now it works just fine!!!
And... jes... i had the cutscenecode twice. Once for each possibility. But i removed it and the problem was solved.
Thank you very much! 
But still i am having difficultys with the "respawn" after exiting the "death-message room" the character does not return into the previous room, even though the room is shown.

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: how to cancel a running timer?
« Reply #5 on: 28 Jul 2012, 00:50 »
And... jes... i had the cutscenecode twice.
Even if my method hadn't made it obsolete, you wouldn't have had to write down the exact same code twice. Just put it inside a function and call that twice:
Code: Adventure Game Studio
  1. function death_scene() {
  2.   ...
  3.   ...
  4. }
  5.  
  6. // in the appropriate place(s)
  7.   death_scene();
Even if the code is merely similar you can do the same thing, just add one or two parameters for the differences in that case. A cornerstone of good programming is getting rid of duplicate code.

Regarding the respawning, if the room is shown, the character is there, too. They might be outside the screen, transparent, behind a walkable area or use an empty sprite, but they must be there because the current room is always the one the player character currently is in.
If debug mode is enabled, test the game and hit Ctrl-D to get an overview of all the characters within the current room.
« Last Edit: 28 Jul 2012, 00:52 by Khris »
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Re: how to cancel a running timer? [SOLVED]
« Reply #6 on: 28 Jul 2012, 20:01 »
Regarding the respawning, if the room is shown, the character is there, too. They might be outside the screen, transparent, behind a walkable area or use an empty sprite, but they must be there because the current room is always the one the player character currently is in.
If debug mode is enabled, test the game and hit Ctrl-D to get an overview of all the characters within the current room.

Well its true, the player is there (logically as you say) but... somewhere totally off space. On a position in the room which is out of any sight (280, 0 or something) which is odd. Even if i interact with other characters in the screen, the dialog will be properly triggered just that i cant walk around and that my playercharacter is not there.

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: how to cancel a running timer? [SOLVED]
« Reply #7 on: 28 Jul 2012, 20:06 »
Well, what are the parameters of the player.ChangeRoom() command?
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Re: how to cancel a running timer? [SOLVED]
« Reply #8 on: 29 Jul 2012, 16:16 »
Thats the function for the "Try again Button":
Code: Adventure Game Studio
  1. function btnDeathButton_OnClick(GUIControl *control, MouseButton button)
  2. {
  3.     gInventory.Visible=true;
  4.     gDeathMessage.Visible = false;
  5.     player.Loop = player_loop;
  6.     player.ChangeRoom(player_Room, player_x, player_y);
  7. }
  8.  
I have created global variables with the name "plaer_loop" "player_Room" "player_x" "player_y". Actually... everything as it should be. I thought.

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: how to cancel a running timer? [SOLVED]
« Reply #9 on: 29 Jul 2012, 17:16 »
So you're setting all these variables at the start of the function that leads to the player's death, right?
Because if you forget to set player_y, it remains 0 and thus the character will be placed at (X, 0), outside the visible area.
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Re: how to cancel a running timer? [SOLVED]
« Reply #10 on: 31 Jul 2012, 21:13 »
So you're setting all these variables at the start of the function that leads to the player's death, right?
Because if you forget to set player_y, it remains 0 and thus the character will be placed at (X, 0), outside the visible area.

That sounds like this might be what happens. I dont set the these variables properly. But how do i do it? Last time i just created the global variables and it worked macikally.

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: how to cancel a running timer? [SOLVED]
« Reply #11 on: 31 Jul 2012, 21:36 »
There's no magic involved; the variables are simply set before the death scene. I remember posting the code but I'm too lazy to search the thread right now.

The logic is this:

// deadly interaction
1. save player's position, direction and room
2. walk player into doom
3. show death GUI
4. if "undo" is selected, restore player to state saved in point 1.

Try to find 1. in your code and post it. It's probably a custom function call.
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Re: how to cancel a running timer? [SOLVED]
« Reply #12 on: 31 Jul 2012, 22:28 »
The only function i have imported (custom made) is this:
Code: Adventure Game Studio
  1. enum CauseOfDeath {
  2.     eDeathTree,
  3.     eDeathSwamp
  4. };
  5.  
  6. import function ShowgDeathGui(CauseOfDeath cod);
  7.  
  8. import function ShowDeathGUI(CauseOfDeath cod);    
  9. String death_message[100];                        //Death message text
  10. int death_picture[100];                           //Death message image
  11.  
But this is actually only concerning the image and the text of a death scene which is obsolet for the current game as the player is just going to hear a diffrent voicefile...

But then i might have this here:
Code: Adventure Game Studio
  1. function on_mouse_click(MouseButton button) {
  2.   // called when a mouse button is clicked. button is either LEFT or RIGHT
  3.   if (IsGamePaused() == 1) {
  4.     // Game is paused, so do nothing (ie. don't allow mouse click)
  5.   }
  6.   else if (button == eMouseLeft) {
  7.     ProcessClick(mouse.x, mouse.y, mouse.Mode );
  8.     player_loop = player.Loop;
  9.     player_x = player.x; player_y = player_y;
  10.     player_Room = player.Room;
  11.   }
  12.   else if (button == eMouseRight || button == eMouseWheelSouth){
  13.     // right-click our mouse-wheel down, so cycle cursor
  14.    mouse.SelectNextMode();                                                                    
  15.   }
  16.   else if (button == eMouseMiddle) {
  17.     // Middle-button-click, default make character walk to clicked area (a little shortcut)
  18.     // Could have been just "player.Walk(mouse.x,mouse.y)", but it's best to
  19.     // leave our options open - what if you have a special script triggered
  20.     // on "walking" mode?
  21.     ProcessClick(mouse.x, mouse.y, eModeWalkto);
  22.   }
  23.   else if (button == eMouseWheelNorth) {
  24.     // Mouse-wheel up, cycle cursors
  25.     // If mode isn't WALK, set the previous mode (notice usage of numbers instead
  26.     // of eNums, when it suits us)...
  27.     if (mouse.Mode>0) mouse.Mode=mouse.Mode-1;
  28.     else
  29.     {
  30.       // ...but if it is WALK mode...
  31.       if (player.ActiveInventory!=null)
  32.       {
  33.         //...and the player has a selected inventory item, set mouse mode to UseInv.
  34.         mouse.Mode=eModeUseinv;
  35.       }
  36.       else
  37.       {
  38.         // If they don't, however, just set it to mode TALK (change this line if you add more cursor modes)
  39.         mouse.Mode=eModeTalkto;
  40.       }
  41.     }
  42.   }
The first lines are what i thought important. I thought this would be enough to save the position of the player. But oubviously its not sufficient enought.

Re: how to cancel a running timer? [SOLVED]
« Reply #13 on: 31 Jul 2012, 22:35 »
.

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: how to cancel a running timer? [SOLVED]
« Reply #14 on: 01 Aug 2012, 01:41 »
There's a typo in there:

player_y = player_y;

is of course supposed to be:

player_y = player.y;
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Re: how to cancel a running timer? [SOLVED]
« Reply #15 on: 01 Aug 2012, 12:36 »
There's a typo in there:

player_y = player_y;

is of course supposed to be:

player_y = player.y;

THATS IT!
Let me call you this: Genious! ;-P
Thank you so mutch, i just dont know how to thank you!
Sutch a tiny mistake i would have never noticed. But now everything works perfect. Now i am so close to create a totally new KingsQuest 7 like game!
Thank you Khris!

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: how to cancel a running timer? [SOLVED]
« Reply #16 on: 01 Aug 2012, 15:00 »
No problem.
It's actually my fault anyway, I corrected the typo back then but didn't mention it later in the thread.
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=45643.msg612779#msg612779
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"