Repeated action, different result

Will.
01 Aug 2013, 07:04
Hi guys,

I am making my first game (newbie here) and there is one instance in my game where I'd like the player to do an action repeatedly, and after a certain number of tries, the outcome changes. Something like this:

>Open door
The door is too tight to be opened.
>Open door
The door is too tight to be opened.
>Open door
The door is too tight to be opened.
>Open door
The door is too tight to be opened.
>Open door
Finally, with a struggle the door came free and smashed against the wall.

I tried using flags like "if flag one is unset, set flag one and say x; if flag one is set, set flag two and say x, if flag two is set, set flag three and say y", but the game did those in one turn and come out with the "y" outcome first time. :| Is there any way to achieve this? Thanks for helping!

The Pixie
01 Aug 2013, 07:54
You should do is as a variable that counts, not as a flag. On the Attributes tab for the door object, add a new attribute called "count", and set it to be an integer.

In your script, you then need to increase count by 1 each time the player tries to open the door ("Increase object counter", under variables), and to test if the number of tries is high enough ("If..." under Scripts).

In code it might look like this, if you want to just past this in:

if (count > 4) {
msg ("Finally, with a struggle the door came free and smashed against the wall.")
// Other stuff
}
else {
msg ("The door is too tight to be opened.")
}
this.count = this.count + 1

Alex
01 Aug 2013, 10:36
You can also nest "first time" scripts to do this.

Silver
02 Aug 2013, 08:02
I don't have any coding advice but how would you let the player know what is expected of them? If I try something and it doesn't work I generally don't try the same thing again unless I'm clutching at straws and even then probably only a second time.

HegemonKhan
02 Aug 2013, 08:07
somewhere, he'd have to put in a hint message of some sort for this, which can be done most commonly (but not only way):

Add a~new script -> Output -> Print a message -> [MESSAGE] -> textual message

or

Add a~new script -> Output -> Print a message -> [EXPRESSION] -> various scripts or script messages

if (count > 4) {
msg ("Finally, with a struggle the door came free and smashed against the wall.")
// Other stuff
}
else {
msg ("The door is too tight to be opened.")
msg ("But, you're stubborn...")
}
this.count = this.count + 1


----------

flags ~ booleans are binary (dualistic~adversarial~opposites): true~false, on~off, yes~no, positive ~ negative, up ~ down, in ~ out, jumping ~ falling ~ walking ~ running ~ flying ~ swimming ~ drowning, blessed ~ cursed, armed ~ unarmed, and etc...

(lots of combination choices of how to use them)

orc.dead=true -> (dead)
orc.dead=false -> (alive)
orc.alive=true -> (alive)
orc.alive=false -> (dead)

orc.flying=true -> (not walking)
orc.walking=true -> (not running)
orc.running=false -> (walking)

light.switched_off=yes -> (unlit)
light.switched_on=no -> (unlit)

etc etc etc

And, they can easily be changed ~ "flagged" (set ~ setted), too:

orc.dead=false -> orc.dead=true -> dead orc

orc.alive=true -> orc.alive=false -> dead orc

and then put with with conditionals (such as "If" script):

if (orc.dead=true) {
player.experience = player.experience + orc.experience
player.cash = player.cash + orc.cash
msg ("You killed the orc!")
} else { // orc.dead=false
player.hp = player.hp - orc.damage
msg ("The orc attacks you!")
}

<object name="orc">
<dead type="boolean">false</dead>
</object>

if (player.attacks) {
orc.dead=true // this changes the orc from being "flagged" as alive to being "flagged" as now dead
msg ("You fatally struck the orc with your sword!")
}

// after the player.attacks script occurs successfully, the orc object now looks like this:

<object name="orc">
<dead type="boolean">true</dead>
</object>

// which would then activate the "if (orc.dead=true), then give the orc's exp and cash to player" script block