Turn script question near end of game

XanMag
If I want a random msg script to run after every 10th turn (or so) after an event happens near the end of my game (after a flag called "exover" is set), what is the best way to do that?

Do I call a function at the same moment?

Do I set a game turn script to trigger if exover = true?

Do I set a run script after 10 turns after the flag is set in the same script?

I know it is simple, but I have ALWAYS had trouble with turn scripts. I loathe them... Your suggestions are appreciated!

XanMag

The Pixie
Create a Boolean attribute called "exover" (you perhaps already have) and an int one called "exovercount" on the relevant object. Then create a script called "changedexover" on it. Have it enable a turn script called "exoverturnscript".

Create a turnscript called "exoverturnscript". Make sure it is not attached to an object or room.
exovercount = exovercount + 1
if (exovercount % 10 = 0) {
msg("Something happens now")
}

XanMag
At the end of a function, I have: SetObjectFlagOn (Commons, "exover")
which allows the player to leave the current room. I want to have random messages pop up every 10th turn or so at this point. At the end of this function (or once the flag is set), I want the random messages to pop up no matter where the player is within the game.

So... I have created a Boolean attribute on a room (Commons) called "exover". In the little box in the GUI... I leave the "True" box unticked? Then, also on the Commons, I created an integer attribute called "exovercount". Do I leave the exovercount integer equal to zero? I also created a "changedexover" script that enables "exoverturnscript".

Then... in the turn script that is not attached to an object, I copy-paste the code you supplied above?

I will have random messages selected at that point every 10th player turn, but I'm pretty sure I can make that work.

If all above is okay, do I have at the end of my function (above) a script that sets the Boolean attribute "exover" to true?

Sorry if I am being daft here, but I really am lame with code stuff and usually I can just hammer it out in trial and error fashion, but if my past experience with turn scripts is any indication, I would goober this thing up beyond repair without help! So, is the above correct?

Thanks.

XanMag

The Pixie
XanMag wrote:At the end of a function, I have: SetObjectFlagOn (Commons, "exover")
which allows the player to leave the current room. I want to have random messages pop up every 10th turn or so at this point. At the end of this function (or once the flag is set), I want the random messages to pop up no matter where the player is within the game.

Right.

So... I have created a Boolean attribute on a room (Commons) called "exover". In the little box in the GUI... I leave the "True" box unticked?


Yes, because it is originally false (flag not set).

Then, also on the Commons, I created an integer attribute called "exovercount". Do I leave the exovercount integer equal to zero?


Yes.

I also created a "changedexover" script that enables "exoverturnscript".

Then... in the turn script that is not attached to an object, I copy-paste the code you supplied above?


Yes.

I will have random messages selected at that point every 10th player turn, but I'm pretty sure I can make that work.

If all above is okay, do I have at the end of my function (above) a script that sets the Boolean attribute "exover" to true?


You already have that, that is what SetObjectFlagOn (Commons, "exover") does.

It is confusing because in the GUI you set flags on and off, and in code you have Booleans that are true or false, but really it is the same thing. Commons.exover is a Boolean in code, and a flag in the GUI and it is all the same thing when the game is played.

HegemonKhan
A Boolean Attribute has only two Values: 'true' or 'false', think of like a light switch of: on vs off, except instead of using the words 'on' and 'off', we're using the words 'true' and 'false'.

in code, as a 'creation' tag block:

<object name="Commons">
<attr name="exover" type="boolean">false</attr>
</object>

~VS~

<object name="Commons">
<attr name="exover" type="boolean">true</attr>
</object>


in code, as Scripting:

Commons.exover = false
~vs~
Commons.exover = true

in the GUI~Editor, as creation:

'Commons' Room Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)

(Object Name: Commons)
Attribute Name: exover
Attribute Type: boolean
Attribute Value: false

~VS~

(Object Name: Commons)
Attribute Name: exover
Attribute Type: boolean
Attribute Value: true

in the GUI~Editor, as a Script:

run as script -> add new script -> variables -> 'Set object flag' Script -> (set it up) // this set's~re-set's its Value to 'true'

~VS~

run as script -> add new script -> variables -> 'Unset object flag' Script -> (set it up) // this set's~re-set's its Value to 'false'

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

these are all (for the most part) the same thing, toggling between the Boolean Attribute having its Value as 'true' vs as 'false'

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

this dualism of 'true' vs 'false', allows simple-to-understand usage of the 'if' Script (shown in code, as Scripting ~ as it's easy and quick for me):

aka: understanding "state flagging" with Boolean Attributes is much easier, than with other types of Attributes

<object name="Commons">
<attr name="exover" type="boolean">false</attr>
<attr name="count" type="int">0</attr> // see if you can understand why this is needed (this is a more advanced-difficult question)
<attr name="changedexover" type="script"><!CDATA[
while (Commons.count < 5) { // see if you can understand why this is needed (this is a more advanced-difficult question)
if (Commons.exover = true) {
msg ("hi")
Commons.exover = false // see if you can understand what's going on here
} else if (Commons.exover = false) {
msg ("bye")
Commons.exeover = true // see if you can what's going on here
}
count = count + 1 // see if you can understand why this is needed (this is a more advanced-difficult question)
}
]]></script>
</object>


whereas, "state flagging", via using Integer or String or whatever Attributes, is a bit more difficult to understand

XanMag
After entering the code Pixie mentioned above... I get the following message at the point where my messages are supposed to start popping up:

Error running script: Error compiling expression 'game.exovercount + 1': ArithmeticElement: Operation 'Add' is not defined for types 'Object' and 'Int32'

Here is the code at the end of the function that begins when entering the room 'Commons':
SetObjectFlagOn (Commons, "exover")


Here is the code for my attributes in the room 'Commons':
    <exover type="boolean">false</exover>
<exovercount type="int">0</exovercount>
<changedexover type="script">
EnableTurnScript (exoverturnscript)
</changedexover>


Here is the 'exoverturnscript':
  <turnscript name="exoverturnscript">
<script>
game.exovercount = game.exovercount + 1
if (game.exovercount % 10 = 0) {
n = GetRandomInt (0, ListCount (game.suntzu) - 1)
msg ("A voice booms over the loud speakers, " + StringListItem (game.suntzu, n))
}
</script>
</turnscript>


Here is an attribute I have set to 'game':
<suntzu type="stringlist">
<value><![CDATA[<b>"I have a whole bunch of my random messages here..."</b>]]></value>
</suntzu>


Again, I get this message:

Error running script: Error compiling expression 'game.exovercount + 1': ArithmeticElement: Operation 'Add' is not defined for types 'Object' and 'Int32'

at the point my messages are supposed to run.

@HK: I tried to answer your questions as I read your post, but I'm afraid I could only reason out answers to the non-difficult-advanced questions. sort of :lol: ... sort of :cry:

@Pixie: I don't have a clue what --> (game.exovercount % 10 = 0) means!

HegemonKhan
your 'exovercount' Integer Attribute was added~created by you to~in~for your 'Commons' Room Object, not your 'game' Game Object, so you need to fix your code lines to match what you did:

from:
game.exovercount = game.exoxercount + 1
to:
Commons.exovercount = Commons.exovercount + 1

from:
if (game.exovercount % 10 = 0) {
to:
if (Commons.exovercount % 10 = 0) {

in~from your Turnscript code below:

  <turnscript name="exoverturnscript">
<script>
game.exovercount = game.exovercount + 1
if (game.exovercount % 10 = 0) {
n = GetRandomInt (0, ListCount (game.suntzu) - 1)
msg ("A voice booms over the loud speakers, " + StringListItem (game.suntzu, n))
}
</script>
</turnscript>


thus, the error message wasn't that helpful, as the reason that the 'game.exovercount' doesn't work (aka: the error message), is because that Attribute doesn't exist in your 'game' Game Object, as you never created it in the 'game' Game Object, whereas you did create it in the 'Commons' Room Object.

------

alternatively, to the above, you could instead, create~add~set the 'exovercount' Integer Attribute upon~inside~to the 'game' Game Object, instead:

(while still using your 'game.exovercount' that you have in your Turnscript's scripts~code)

'game' Game Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)

(Object Name: game)
Attribute Name: exovercount
Attribute Type: int (integer)
Attribute Value: 0

<game name="blah">
<attr name="exovercount" type="int">0</attr>
</game>


instead of adding it to your 'Commons' Room Object.

-------

remember the syntax for Attributes, is this:

Object_name.Attribute_name
~and~
Object_name.Attribute_name = Value_or_Expression

game.exovercount ~~~ would be an Attribute (created~set) in (added to) your 'game' Game Object

Commons.exovercount ~~~ would be an Attribute (created~set) in (added to) your 'Commons' Room Object

these are two different Attributes, even though they have the same name.

take for example:

orc.strength = 25
vs
dragon.strength = 75

obviously, these are two different Attributes, and need to be used correctly~appropriately. The 'strength' Integer Attribute on the 'orc' Object does not have the same Value as the 'strength' Attribute on the 'dragon' Object. If I were to add +5 strength to the Orc's strength, the Dragon's strength doesn't become 80.

-------

Q: quotient
R: remainder

111 divided by 10 equals: Q11, R1

the ' % ' Operator is a division Operator, except it finds the remainder instead of the quotient:

111 / 10 = 11
vs
111 % 10 = 1

10 / 10 = 1
vs
10 % 10 = 0

20 / 10 = 2
vs
20 % 10 = 0

-----------

the % Operator (called 'Modulus' btw), enables you to do some really cool things, for examples:

determine whether a randomly generated number is even or odd:

(math: any number divided by 2 without a remainder, aka: R=0, is even)
(for example: 31983791287389172 / 2 ====> 0 ----> even)

random_number = GetRandomInt (0, 1000)

if (random_number % 2 = 0) { // if ( Remainder = 0)
msg ("The random number " + random_number + " is even")
} else {
msg ("The random number " + random_number + " is odd")
}


determine whether a randomly generated number is divisble by some factor or not:

(math: any number is divisible by a factor if there's no remainder, aka: if R=0, then the factor is divisible into that number)
(10 / 5 ====> Q2, R0 -----> 10 is divisible by 5)
(125 / 5 ====> Q25, R0 -----> 125 is divisible by 5)
(125 / 6 ====> Q20, R0.83 = R(5/6) -----> 125 is NOT divisible (evenly) by 6)

get input {
factor = result
}

random_number = GetRandomInt (0, 1000)

if (random_number % factor = 0) {
msg ("The random number " + random_number + " is divisible by " + factor)
} else {
msg ("The random number " + random_number + " is not divisible by " + factor)
}


Cyclic Usage, example:

what month is it in a given random amount of days passed (assumming that jan was the first month of the first 31 days of the random amount of days passed, and that every month has 31 days, of course, for this example only)

days = GetRandomInt (0, 1000)

month = ( (days / 31) % 12 ) + 1
// the '+1' is so that I can use '1-12' instead of having to use '0-11' in the 'if' block below

if (month = 1) {
msg ("Jan")
} else if (month = 2) {
msg ("Feb")
} else if (month = 3) {
msg ("Mar")
} else if (month = 4) {
msg ("Apr")
} else if (month = 5) {
msg ("May")
} else if (month = 6) {
msg ("Jun")
} else if (month = 7) {
msg ("Jul")
} else if (month = 8) {
msg ("Aug")
} else if (month = 9) {
msg ("Sep")
} else if (month = 10) {
msg ("Oct")
} else if (month = 11) {
msg ("Nov")
} else if (month = 12) {
msg ("Dec")
}

HegemonKhan
as for my previous (2 posts back) post's challenge questions for you XanMag:

the 'count' Attribute, the 'count = count + 1', and 'while (count < 5) { scripts }' is so that the looping Function will end after 5 loops, we don't want it to run forever!

the 'exover = true' and 'exover = false' inside of the 'if (exover = false)' and 'if (exover = true)' respectively, is to enable the 5 loops of the Function, to switch between displaying 'hi' and 'bye', as this should be the output:

bye
hi
bye
hi
bye

XanMag
That was quite the over sight on my part, huh? Simple, so I feel dumb I didn't recognize that!

The more I delve into the belly of Quest (aka the more I work with the code and the more I ask on these forums)... the more I understand your posts, HK! *thumbs up*

And, Holy Moly! I just ran through my walk through and ... IT WORKED!!!

Thanks to the both of you! Again! Now to finish this game!

XanMag

XanMag
Also... at the end of my game (or at the appropriate point in my game), can I just drop the flag "exover" and the random messages will stop?

HegemonKhan
depending on how you setup the Turnscript's execution, there's two ways:

1. if you used Pixie's 'changed' Script way, you need to change the design to using an 'if' block:

(my syntax may be off, look it up for correct syntax if this doesn't work ~ it's been awahile since I've done quest coding due to school and am too lazy to look up the syntax myself, lol)

<object name="Commons">
<attr name="exover" type="boolean">false</attr>
<attr name"exovercount" type="int">0</attr>
<attr name="changedexover" type="script">
if (Commons.exover = true) {
EnableTurnscript (Commons, "exoverturnscript")
} else if (Commons.exover = false) {
DisableTurnscript (Commons, "exoverturnscript")
}
</attr>
</object>


and then in a script when you want, you just got to change the 'Commons.exover' Attribute's Value back to 'false', via: 'Unset object flag' Script: or in code: SetObjectFlagOff (Commons, "exover"), which will disable the 'exoverturnscript' Turnscript.

(you can't just use the script that disables the Turnscript, as the Turnscript will just be RE-enabled, due to the 'changed' Script in your 'Commons' Room Object, as your 'Commons.exover' Attribute's Value is still 'true')

2. if you just used the 'set object flag' Script, in code: SetObjectFlagOn (Commons, "exover"), then you just need to disable the Turnscript again, when you want to, via: 'Set object flag' Script or in code 'SetObjectFlagOff (Commons, "exover").

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

Support

Forums