How to end the game?
NecroDeath
27 Sept 2016, 22:00After 3 weeks I have my first game done, but I don't know how to set (multiple) conditionals to trigger 'end the game'.
The player has to return to their home (room) and if they have all the items they need in their inventory the game ends.
hegemonkhan
27 Sept 2016, 23:55the conditionals is via using the 'if' Script, and you literally can use 'and' or 'or' (in your case, I believe you want 'and', if I understand correctly) for connecting as many conditionals as you want. Though the caveat is that each conditional must be a full statement.
------------------------------
a full quest code statement has this form/syntax:
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE
~ or ~
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION
---------------------
to end the game:
in code: finish
in the GUI~Editor: (run as script) -> add new script -> '?game?' section/category -> 'finish the game' (or something like this) Script
-------------
so, for an example:
'room' Object -> '?Scripts?' Tab -> 'onenterroom' Script -> (see below)
(run as script), or set the 'onenterroom' type from [string] to [script] -> add new script -> 'scripts' section/category -> 'if' Script -> (see below, for an example)
if [EXPRESSION] NAME_OF_ITEM_1.parent = player and NAME_OF_ITEM_2.parent = player and NAME_OF_ITEM_3.parent = player and ... etc etc etc conditionals (or less)
// just to make clear the full statements for you, using parenthesis:
// if [EXPRESSION] (NAME_OF_ITEM_1.parent = player) and (NAME_OF_ITEM_2.parent = player) and (NAME_OF_ITEM_3.parent = player)
then,
-> add new script -> '?game?' section/category -> 'finish the game' (or something like this) Script
-------------------
an in-code example:
<object name="room">
// actually, I'm not sure how the 'onenterroom' Script looks/works (and am too lazy to open up quest to find out), so the below syntax/header/signature/etc for it, could be wrong:
<attr name="onenterroom" type="script">
if (ball.parent = player and book.parent = player and hat.parent = player and candy.parent = player and wallet.parent = player and necklace.parent = player) {
msg ("Congratulations, you won the game!") // forgot to mention putting in (adding) this 'msg' (Print a message) Script in the GUI~Editor section above
finish
}
</attr>
</object>
if you use the 'onenterroom' Script, then you'll have to have the required items in your inventory, ALREADY BEFORE, you then move to/into the 'room' Room Object. You can't put the item into your inventory while in the 'room' Room Object, as that doesn't trigger/re-trigger the 'onenterroom' Script, which is what does the checking of if you got the items in your inventory, determining whether you win the game or not.
XanMag
28 Sept 2016, 02:41My solution:
- Go to the attributes tab of your room. From this point forward I am going to call the room 'home'. Click it.
- Click the add button just above the bottom box.
- Type in InvCount. Enter.
- Select Integer from the down menu and set the value to a number equal to the number of items required in your inventory to win.
- Click on InvCount in the attributes list again and click on Add Change Script.
6a. Click on the change script. It should be named changedInvCount
6b. To this section add: If object attribute equals Object home Attribute InvCount = 0, 'then' print message, "It appears you have everything you need to win the game. Now just to get back home." Or something like that. This would be good assuming that the final object isn't picked up in the 'home' room.
7a. Go to the room 'home' and click on the Scripts tab. Add this to the 'After entering room' section.
7b. Add another 'If' script. Add this: If object attribute equals Object home Attribute InvCount = 0
7c. Then: Run whatever scripts you want to run at the end of the game. (see optional below)
8a. Go to each object that is required to have in your inventory at game end. Under the take option, switch the choice from 'default' to 'run a script'. Make sure you add the following script first. Add to inventory 'this object's name'.
8b. Add to this same script the following... Set variable -- home.InvCount = expression home.InvCount - 1
9a. If you can drop the object, then you need to reverse 8a and 8b. Go to the drop option under the inventory tab for this object and add 'move object to current room - 'this object' and add Set variable -- home.InvCount = expression home.InvCount + 1
9b. If the object is not able to be dropped, then ignore step 9a.
Optional:
- If you want a message to print when you enter the room if the player is not carrying all that they must be to win the game, you can add 'Else If' scripts to the changedInvCount 'If' script. In the 'Else If's here just do this: Add a script here and choose object attribute equals Object home Attribute InvCount = x ..... where x equals the number of objects remaining needed to win the game. You could add a 'print message' script like "It appears you are getting close to winning the game, but you are still missing 'x' number of items. Good luck hunting for them." Or, something like that.
It's been a while since I tinkered on Quest, but this is a solution I became familiar with and used it quite often in my games. Someone out there, if this is not a reasonable solution, please point out my errors or a simpler way to get it done. I guess the complexity of the game-end script here is largely dependent on how many objects are needed in the inventory to win the game.
If you have any questions, please let me know! Happy Gaming!
XanMag
hegemonkhan
28 Sept 2016, 09:36err, whoops on my part...
XanMag's mentioning of using 'afterenteringroom' Script would be better than my worse use of 'onenterroom' Script, my apologies (I'm not that familiar with the built-in stuff).
... or maybe it doesn't matter... which one you use... meh... Pixie or Jay can jump in on which one would be better, as they understand this stuff way better than I, lol.
NecroDeath
28 Sept 2016, 13:45Thanks again, this forum is awesome.