Pages: 1 2
Author Topic: game end EVENT issues  (76,233 Views)
Offline (Unknown gender) Goombert

Developer
Joined: Jan 2013
Posts: 2,991
View profile
Reply #15 Posted on: May 24, 2014, 01:44:31 AM
You could thread your code with script_thread and just block game end with sleep()
Offline (Unknown gender) Darkstar2

Member
Joined: Jan 2014
Posts: 1,238
View profile
Reply #16 Posted on: May 24, 2014, 02:04:38 AM
lol.

Could you please give me an example?

Let's say I am inside a game window and click the "X" to close the window, before the program exits, I would like a page to display a message and wait 10 seconds or wait for any key then game end.

BTW when using script thread, do I have to end the thread or close it, or is this done automatically upon the return from the script ?


Offline (Unknown gender) Goombert

Developer
Joined: Jan 2013
Posts: 2,991
View profile
Reply #17 Posted on: May 24, 2014, 02:31:19 AM
Just put this code in game end and make your myadvertisementscript set global.readtofinish to true whenever it is finished.
Code (EDL) Select

global.readytofinish = false;
var thread;
thread = script_thread(myadvertisementscript, 0, 0, any other parameters...);
while (!global.readytofinish) {
  sleep(1000);
}

Offline (Unknown gender) Darkstar2

Member
Joined: Jan 2014
Posts: 1,238
View profile
Reply #18 Posted on: May 24, 2014, 02:47:27 AM
Thanks :D

BTW, why do I have to use thread=script_thread, can't I call script_thread directly ?

Offline (Unknown gender) Goombert

Developer
Joined: Jan 2013
Posts: 2,991
View profile
Reply #19 Posted on: May 24, 2014, 07:33:41 AM
Yes you can but you may want to keep the id for thread_get_return or something, idk, it was just pseudo-code.
Offline (Unknown gender) Darkstar2

Member
Joined: Jan 2014
Posts: 1,238
View profile
Reply #20 Posted on: May 24, 2014, 08:04:41 AM
Oh I forgot about that ...
ok used alone if not using a return value
and index if using a return value.
much like a regular script

Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #21 Posted on: May 24, 2014, 11:08:08 AM
QuoteHowever I have a question, it looks like the game end event executes everything linearly (not like a step)
EVERYTHING in ENIGMA executes linearly. Including step event. So of course you cannot drawn anything from game end event to the screen, just like you cannot do it from step or key press. Drawing happens in draw event. What you want is "Close button" check event and Esc key event. There you check if the user wants to close your game. Then you set a variable like "close_popup = true; alarm[0] = room_speed*3;" and in draw event do "if (close_popup == true) draw_text("Game will end in 3 seconds!");". In alarm[0] you just put game_end(). Or you can just do "room_goto(room_end);" and then have an alarm to end it there.

So what game end event does is call the event when the game ends (magical, isn't it?). And after that event there isn't any other event. So no drawing, no step, no alarm, nothing. It's the last event your game calls. So you shouldn't add text prompts in there. The point of game end event is to release resources, change back resolution, write save to file and so on.
Pages: 1 2