Where do I put the end game condition [SOLVED]

Started by necroshey, Sun 14/02/2016 13:41:31

Previous topic - Next topic

necroshey

Hi there everyone,

As the title says I cannot understand where to put my end game conditions code. As my game is small it doesn't have much, but at least I want it to have a proper way to end. I figured I can use the EndCutscene function to create my end cutscene, but where do I leave the conditions ? I tried putting them in a custom function, but it never triggers. I may have botched it a little bit.

Code: ags
 
function Ending()
{
if((cAsparuh.HasInventory(iHayPiece)) && (cSoldier_Fort.HasInventory (iSwords))){
  DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  surface.DrawImage(270, 200, 41);
  surface.Release();
  Wait(100);
  QuitGame(1);
}
}


One more thing, as you might have seen in the code I used DrawImage. I use it a lot in my game, since all the characters don't "speak", but rather pop up speech bubbles with images in them (so as to make it more language neutral). I create a backup and then use DrawImage to draw the bubbles and then return the backup, to create the illusion of speech bubbles. However, I cannot make it in such a way that you can click with the left mouse button and the bubble disappears, I can only make it with the Wait() function. Is there someone that knows a little bit more and can help me with my problems ? All advice are appreciated. Sorry for the language, English isn't my mother tongue. 

Danvzare

Firstly, your code works perfectly. I tried it myself, it works. Which tells me something else is the problem, not the function you wrote. Which means you will have to give a bit more detail; such as where the function was defined, where you're calling it from, and whether or not the code that calls it is even running when it's supposed to.
Secondly, the EndCutscene() function is used to mark where a cutscene ends, not to mark that this is the final cutscene in the game. You generally enclose code you want the player to be able to skip, between StartCutscene() and EndCutscene() functions.

For example:
Code: ags

StartCutscene(1);
Ending();
EndCutscene();
QuitGame(1);


As for your other problem. I've never used the DrawImage() function before, nor have I ever attempted to make speech bubbles. So unfortunately I can't answer that one. But someone else here probably can.

necroshey

Hi Danvzare,

I had a feeling the code wasn't broken, but it just doesn't trigger at all. I've put it in the end of the GlobalScrip.asc , but nothing happened. Then I tried putting it in the script fof my final final room at the end again, but same effect. I also tried just writing the if statement without a function in the global script, but it gave errors (I assume you can't not use functions), but is there a function that acts like a main and that checks all the time for the stuff ?

Crimson Wizard

#3
Any function must be called from somewhere to do work. There are two kinds of places where you can call your custom functions from: "repeatedly_execute" function, which is called every game tick (and its counterparts, such as repeatedly_execute_always - you may check manual for explanation on their differences), and event handlers, which are triggered on button press, mouse click on character, etc.

"repeatedly_execute" function may generally serve for your purpose, but when it is something that may only occur once in whole game, it may worth to try out a different approach.

Since your "game over" condition is based on two characters having particular inventory, you may as well just call your function "Ending" after giving each of them corresponding item. Game will only end after both characters have items (which means that Ending() will be called twice: first it won't do anything, and second time it will end the game).

In the end, choose a variant which works best for your game.

necroshey

Hi Crimson Wizard,

Thanks a lot for that. I'm not a pro at coding, but I'm slowly learning and forgot about that small part where functions must be called :D Now if only I could solve that DrawImage problem it'd be great, but I'll continue experimenting. For now this was a big deal for me, so thanks for the help.


necroshey

Thank you Khris, that worked marvellously :smiley: I'm really happy that everyone here decided to share their wisdom and help. Thanks everyone! :-D

SMF spam blocked by CleanTalk