counter

Xecutioner
11 May 2014, 03:42
Hey, I'm sorry if this is a bit of a noobish question. But can I make a counter? Like when something happens one gets added to said counter. When it builds up to a higher number, it performs an action, and restarts. Is it possible to do?

HegemonKhan
11 May 2014, 06:27
there's a built-in counter function in the GUI~Editor, but it can only increase~increment by +1, so it's just better to make your own:

in some script (Function, Verb, Command, Turnscript, Timer, etc):

run as script -> add a script -> variables -> set a variable or attribute:

Object.Attribute = Object.Attribute + Value

an example: player.strength = player.strength + 5

conceptually how it works:

old~initial amount: player.strength = 0
player.strength (new) = player.strength (old) + Value
player.strength (new) = 0 (old) + 5 (Value)
new amount: player.strength = 5
old amount: player.strength = 5
player.strength (new) = 5 (old) + 5 (Value)
new amount: player.strength = 10
etc etc etc

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

again, in some script:

run as script -> add a script -> scripts -> if -> [EXPRESSION] -> player.strength = 10 ->
-> add a script -> output -> print a message -> [MESSAGE] -> You've reached 10 strength, now it'll reset back to 0 strength. ->
-> add a script -> variables -> set a variable or attribute -> player.strength = 0

in code:

<object name="player">
-> <inherit name="player_editor" />
-> <attr name="strength" type="int">0</attr>
</object>

<function name="blah">
-> player.strength = player.strength + 5
-> if (player.strength = 10) {
->-> player.strength = 0
->-> msg ("You've reached 10 strength, now it'll reset back to 0 strength.")
-> }
</function>

Espera
19 May 2014, 21:12
Yes, you can absolutely do what you want, and it's not too hard. Frst, give the player or the game a new attribute. Make it an interger, and likely start it at 0. Now, you can have one of both of two things happen. Make it so other scripts include 'increase object counter' found under Variables, or 'set object variable or attribute' also found under Variables. You chose them based on whether you want the counter to go up by 1 or more than 1. 'Increase Object Counter' is simpler, and will make the attribute in question increase in value by 1. 'Set Object Variable or Attribute' is for when you want the value to go up by more than one, and has to be done like this: 'player.attribute expression player.attribute + 3' (just as an example.)

The other thing you can do is in game scripts, you can add a turn script. This could simply be to do the increase object counter. You can have it happen quietly, or have the game post a message like 'You feel the corruption building inside you', or whatever. This makes it so with every action the player takes, the count goes up.

Finally, you'll want to make a turn script in game which is like so. 'If object player counter attribute < number 100 (or whichever) and then have your consequence happen, and if you want it to be cyclical, include in your results a 'set object variable or attribute' script that simply reads 'player.attribute expression 0' to reset the counter to 0 and start the process all over again. The 'if' statement you use in this case is 'object counter' near the top of the list. It allows you to specify =, <, >, or combinations thereof.

And there you have it.

HegemonKhan
20 May 2014, 01:19
just in case, either of you are not aware:

you can do more than just add and subtract... see examples below

Addition: Object.Attribute = Object.Attribute + Value
Subtraction: Object.Attribute = Object.Attribute - Value
Multiplication: Object.Attribute = Object.Attribute * Value
Division: Object.Attribute = Object.Attribute / Value

you can probably do a few other math operations, like exponents, square roots, and etc, but I'm not sure

also, you can use other attributes too for your 'Values', for examples:

Object.Attribute = Object.Attribute + Object2.Attribute2
player.cash = player.cash + orc.cash
player.current_hit_point_integer = player.current_hit_point_integer - orc.physical_damage_integer

including making full fledge math equations~formulas~game mechanics, (aka Expressions):

player.physical_damage_integer = weapon.physical_damage_integer + weapon.physical_damage_integer * (player.strength_integer - orc.endurance_integer)

including calling functions too:

player.physical_damage_integer = critical_hit_function (player) * weapon.physical_damage_integer + weapon.physical_damage_integer * (player.strength_integer - orc.endurance_integer)

// player -> object_x

<function name="critical_hit_function" parameters="object_x" type="int">
-> if (RandomChance (object_x.luck_integer) = true) {
->-> value_x = 2
-> } else {
->-> value_x = 1
-> }
-> // this code line below, will replace the 'critical_hit_function (player)' in the Expression code line (the equation~formula) above, with either 1 or 2
-> Return (value_x) // the R might need to be lower case, as I can't remember if it's upper or lower case, lol
</function>