Problem with getting turn scripts to work

Eaten By A Grue
Hi! A game I'm working on includes a bottle of wine item which can cause intoxication that gradually fades (or if you drink too much, you pass out for a bit and it 'resets'). I implemented this by making 'drink wine' run turn scripts that do different things depending on the player's current alcohol level. It works well at first but the timing becomes odd if the player drinks multiple times. What I want to happen is --

If the player drinks when sober, they go to level one for ten turns then go back to zero.
If the player drinks at level one, they go to level two for ten turns then go back to level one (and then return to level zero after another ten turns).
If the player drinks at level two, they reset to zero right away.

Here is what this section looks like in the code view. Maybe someone could spot a mistake or let me know if there's a better way to do this!

<drink type="script"><![CDATA[
IncreaseObjectCounter (player, "alclevel")
if (GetInt(player, "alclevel") = 1) {
msg ("You take a healthy gulp of wine. It's got quite a kick to it, and you feel light-headed almost at once.")
SetTurnTimeout (10) {
if (GetInt(player, "alclevel") = 1) {
msg ("<br/>Your head feels perfectly clear again.")
DecreaseObjectCounter (player, "alclevel")
}
}
}
else if (GetInt(player, "alclevel") = 2) {
msg ("You take another healthy guzzle from the bottle. You're starting to feel more confident. And tough! In fact, you feel like you could take on the world and lick it with one hand tied behind your back! You're not scared of anything!")
SetTurnTimeout (10) {
if (GetInt(player, "alclevel") = 2) {
msg ("<br/>You're beginning to sober up, and your bravado fades a little as you remember the dangers of your situation.")
DecreaseObjectCounter (player, "alclevel")
SetTurnTimeout (10) {
if (GetInt(player, "alclevel") = 1) {
msg ("<br/>Your head feels perfectly clear again.")
DecreaseObjectCounter (player, "alclevel")
}
}
}
}
}
else if (GetInt(player, "alclevel") = 3) {
msg ("You take a long, sloppy draft from the bottle. You're so plastered now you're having trouble staying upright. You sit down, head spinning, and clutch the bottle, the beautiful, beautiful bottle, like a lifeline in a storm.<br/><br/>After a few minutes of frantic effort by your liver, you jerk awake, feeling a little sick, but sober.")
DecreaseObjectCounter (player, "alclevel")
DecreaseObjectCounter (player, "alclevel")
DecreaseObjectCounter (player, "alclevel")
}
]]></drink>

jaynabonne
It looks reasonable to me. I tried it out and didn't see a problem (yet). Do you have a command sequence that shows the problem? It might be some sort of edge case.

Also, is this the online editor or the desktop (Windows) one?

jaynabonne
Actually, I take it back - it depends on how you define "works". If you want there to always be a ten turn delay, then you can't use it the way you are, as the old turn timeout scripts are still in operation. So if you do this:

drink (level = 1)
drink (level = 2)
drink (level = 3)
wait 5 turns
drink (level = 1)

then the script from the first drink will kick in on the next turn. As far as I know, there is no way to kill a "turn timeout" script (there might be, but I haven't researched it yet - there's definitely nothing simple).

The most straightforward way to do what you want is have a real turnscript instead, something that runs after each turn. Then you can handle the different alcohol levels yourself. You'll also have to track the number of turns that have elapsed, but that is the benefit, as it allows you to reset the turn count when things change, so you can always make things kick in ten turns hence.

Edit: What you could do: have an alcohol level on the player. Whenever they drink, add 10 to it. On each turn, via the turn script, if their alcohol level is not zero, decrement it by 1, with your messages ocurring at 0 and 10. If when you add 10 to the drink level, it exceeds 20, then it's the "drunk too much" case, and you do the pass out thing and return the alcohol level to 0.

HegemonKhan
there's two types of 'counting' :

1. 'tally' counting: you just keep increasing this number: game.turns = game.turns + 1
2. cyclical counting: when you hit a certain number, it resets: game.turns = (game.turns + 1) % 5

the modulus operator (division but only returns the remainder instead): %

+1, % 5

0
(0+1) / 5 -> R: 1
(1+1) / 5 -> R: 2
(2+1) / 5 -> R: 3
(3+1) / 5 -> R: 4
(4+1) / 5 -> R: 0
(5+1) / 5 -> R: 1
(6+1) / 5 -> R: 2
(7+1) / 5 -> R: 3
(8+1) / 5 -> R: 4
(9+1) / 5 -> R: 0
etc etc etc

-------------------------

what method do you need for doing what you want (I'm still trying to figure out exactly what you want done, lol) ??? :

(within the) Turnscript:

1. tally: if (x=1) do this 1, if (x=2) do this 2, etc etc etc
2: cyclical: if (x=0), do this thing
3. tally + cyclical (having these as seperate attributes, but the tally is used by the cyclical ~ hopefully you understand this method's application as I'm baffled at how to explain it, lol): x=x+1, y = x % 5, if (y=0) do this thing

<game name="blah">
// day_tally = day_tally + 1
// day_tally = 90
// pretend all months are 30 days long, and ignore all the other complexity that I'm ignoring with my example of calender attr
// day_of_the_month = ( day_tally % 30 ) + 1 = 1
</game>

<turnscript name="blah">
<enabled />
<script>
if (day_of_the_month % 7 + 1 = 1) {
day_of_the_week = "monday"
} else if (day_of_month % 7 + 1 = 2) {
day_of_the_week = "tuesday"
} else if...
etc etc etc
}
</script>
</turnscript>

Eaten By A Grue
Thanks for the help! I'll try the universal turn script thing and see if I can get it to work. This is on the desktop version by the way. One more question; I also need the game to be able to tell when the player is at 'level two' because one puzzle is a door that's treated as locked until the first time you pass through it at that level (because it's a scary cave, and you have to find something that gives you courage); can I still do that using the changes you suggested?

jaynabonne
If you go with what I suggested, then it would be your level 2 if the alclevel is between 11 and 20.

I just realized what I had suggested won't work exactly. Just adding 10 will give you the same problem you had before (e.g. if the level has decreased to 1 and you add 10, it will then be 11 and drop level on the next turn). You need to round up to the nearest 10 after adding 10. I can post code later if you like (I'm at work now.)

HegemonKhan
I forgot that there's a 3rd way as well:

3. using a 'range', for example, inside a turnscript:

if (x > 0 and x <= 5) {
// do this 1
} else if (x > 5 and x <= 10) {
// do this 2
} else if...
// etc etc etc
}

----------------------------

turnscripts are 'always activating' functions, so you want your 'if~else if~else' condition scripting within the turnscript (and if you want to do any counting, then this as well too, obviously), so these are very useful for constantly checking as to whether to do an action for you, for another example:

<turnscript name="leveling_turnscript">
// leveling_function:
// if (player.experience >= player.level * 100 + 100) {
// player.experience = player.experience - player.level * 100 + 100
// player.level = player.level + 1
// leveling_function (repeating this script block)
</turnscript>


----------------------------

the other option is using the 'changed' Script attribute:

whenever 'whatever' attribute's value changes, do whatever script(s) ~ aka do anything you want

jaynabonne
Here's code that should do what you want (take what you need from it in terms of the command):

<!--Saved by Quest 5.5.5328.26617-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="drinktest">
<gameid>f9a6d4f3-d97c-4fe0-a0f1-362733077258</gameid>
<version>1.0</version>
<firstpublished>2014</firstpublished>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<alclevel type="int">0</alclevel>
<drink type="script"><![CDATA[
if (player.alclevel = 0) {
msg ("You take a healthy gulp of wine. It's got quite a kick to it, and you feel light-headed almost at once.")
player.alclevel = 10
} else if (player.alclevel <= 10) {
msg ("You take another healthy guzzle from the bottle. You're starting to feel more confident. And tough! In fact, you feel like you could take on the world and lick it with one hand tied behind your back! You're not scared of anything!")
player.alclevel = 20
} else {
msg ("You take a long, sloppy draft from the bottle. You're so plastered now you're having trouble staying upright. You sit down, head spinning, and clutch the bottle, the beautiful, beautiful bottle, like a lifeline in a storm.<br/><br/>After a few minutes of frantic effort by your liver, you jerk awake, feeling a little sick, but sober.")
player.alclevel = 0
}
]]></drink>
</object>
</object>
<turnscript name="alclevel_turnscript">
<enabled />
<script><![CDATA[
if (player.alclevel <> 0) {
player.alclevel = player.alclevel - 1
if (player.alclevel = 0) {
msg ("<br/>Your head feels perfectly clear again.")
} else if (player.alclevel = 10) {
msg ("<br/>You're beginning to sober up, and your bravado fades a little as you remember the dangers of your situation.")
}
}
]]>
</script>
</turnscript>
<command name="drinkcommand">
<pattern>drink</pattern>
<script>
do(player, "drink")
</script>
</command>
</asl>

The core parts are the "drink" script:

      <drink type="script"><![CDATA[
if (player.alclevel = 0) {
msg ("You take a healthy gulp of wine. It's got quite a kick to it, and you feel light-headed almost at once.")
player.alclevel = 10
} else if (player.alclevel <= 10) {
msg ("You take another healthy guzzle from the bottle. You're starting to feel more confident. And tough! In fact, you feel like you could take on the world and lick it with one hand tied behind your back! You're not scared of anything!")
player.alclevel = 20
} else {
msg ("You take a long, sloppy draft from the bottle. You're so plastered now you're having trouble staying upright. You sit down, head spinning, and clutch the bottle, the beautiful, beautiful bottle, like a lifeline in a storm.<br/><br/>After a few minutes of frantic effort by your liver, you jerk awake, feeling a little sick, but sober.")
player.alclevel = 0
}
]]></drink>

and the turn script:

  <turnscript name="alclevel_turnscript">
<enabled />
<script><![CDATA[
if (player.alclevel <> 0) {
player.alclevel = player.alclevel - 1
if (player.alclevel = 0) {
msg ("<br/>Your head feels perfectly clear again.")
} else if (player.alclevel = 10) {
msg ("<br/>You're beginning to sober up, and your bravado fades a little as you remember the dangers of your situation.")
}
}
]]>
</script>
</turnscript>

Let me know if you have any questions or problems.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums