Increasing the Value of an Attribute

Can't seem to find an option for this, I know there is a way how of course but I can't understand half of the options anyway. I'm trying to increase the value of an attribute by 60 every 5 turns.


in the GUI/Editor script options, you only got the 'increase/decrease counter' Scripts (a 'counter' is just a common name used for an Integer Attribute), but they only do: +1/-1

in the GUI/Editor, to do multiplication/division and/or by a Value more than +1/-1, you got to script it yourself, which is done via the 'set a variable or attribute' Script:

run as script -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)

// basic/simple expressions:

// addition:
set variable NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE = [EXPRESSION] NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE + VALUE

// subtraction:
set variable NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE = [EXPRESSION] NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE - VALUE

// multiplication:
set variable NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE = [EXPRESSION] NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE * VALUE

// division:
set variable NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE = [EXPRESSION] NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE / VALUE


for what you want (+60), an example:

// in code scripting: game.turns = 0 // in GUI/Editor: set variable game.turns = [EXPRESSION] 0
set variable game.turns = [EXPRESSION] game.turns + 60


but, the more tricky part is how to do it every 5 turns, see below, for an example:

I'm using the 'modulus' operator (%), which does division, except it finds/gets the REMAINDER.
(the remainder/modulus lets you do some really neat stuff: cyclic, even/odd, and factoring/divisible-bility)

<game name="example_game">
  <attr name="turns" type="int">0</attr>
  <attr name="example_integer_attribute" type="int">0</attr>
  <attr name="changedturns" type="script">
    if (this.turns % 5 = 0) {
      this.example_integer_attribute = this.example_integer_attribute + 60
      // the only problem with this code, is that it'll also add 60, if you lower your 'game.turns' to a multiple of 5 as well...
    }
  </attr>
  <attr name="statusattributes" type="simplestringdictionary">turns = Turn: !; example_integer_attribute = Example Integer Attribute: !</attr>
</game>

to do the 'if' Script in the GUI/Editor, you got to code it in as well, which is done via:

run as script -> add new script -> 'scripts' section/category -> (see below for example)

if [EXPRESSION] this.turns % 5 = 0


So why would this not work?

set (Time, "minutes", 0)
SetTurnTimeout (5) {
"minutes" = "minutes" + 60
}


As long as you have an object named Time:

Time.minutes = 0
SetTurnTimeout (5) {
  Time.minutes = Time.minutes + 60
}

To test it:

Time.minutes = 0
SetTurnTimeout (5) {
  msg ("Running minutes script...")
  Time.minutes = Time.minutes + 60
  msg (Time.minutes)
}

If I read K.V.'s statement correctly, you typed it in wrong.

I didn't even know there was a "SetTurnTimeout" function...


...or:

EDITED:

set (Time, "minutes", 0)
SetTurnTimeout (5) {
  set (Time, "minutes", Time.minutes + 60)
  msg (Time.minutes)
}

Can you please tell me why you need "time.minutes" to be "time.minutes + 60".

You'll get something like:

5+60 = 65

Do you want your clock to be read like that?


I didn't even know there was a "SetTurnTimeout" function...

Me neither!

It's just 'Run script after a number of turns'. (I had to look, though!)


Ha yes I knew it'd be easier by making time an object.


To calculate the actual amount of time since play began (not counting while, wait, get input, and such):

x = game.timeelapsed  // timeelapsed is a default attribute on the game object
game.hours = x / 3600
time = x%3600
game.minutes = x/60
x = time%60
game.seconds = x
if (game.minutes<10) {
  game.minutes = "0" + game.minutes
}
if (game.seconds<10) {
  game.seconds = "0" + game.seconds
}
game.realgametime = game.hours + "h" + game.minutes + "m" + game.seconds + "s"

K.V wouldn't the second script just set the "minute" attribute to 60 every 5 turns over and over again?


This game uses Pixie's library:

http://textadventures.co.uk/games/view/rr9vezzxkeaovamsaqgxcw/they-call-ya-mister-quest-prototype-in-progress

https://github.com/ThePix/quest/wiki/Clock-Library

VIEW SCREENSHOT

image


UPDATED

OLD CODE HERE
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Every Five Turns">
    <gameid>fbc19c77-e130-4b43-bbdc-e97f1095ec04</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <roomenter type="script">
    </roomenter>
    <start type="script">
      game.turns = 0
      game.minutes = 0
      game.hours = 0
    </start>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <turnscript>
    <enabled />
    <script>
      game.turns = game.turns + 1
      game.minutes = game.minutes + 12
      if (game.minutes = 60) {
        game.hours = game.hours + 1
        game.minutes = 0
      }
      msg (game.minutes)
      if ((game.turns%5)=0) {
        msg ("60 more!")
      }
    </script>
  </turnscript>
</asl>

Every Five Turns

You are in a room.

> z
Time passes.
12

> z
Time passes.
24

> z
Time passes.
36

> z
Time passes.
48

> z
Time passes.
0
60 more!


This is even better:

CLICK HERE TO VIEW CODE
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Every Five Turns">
    <gameid>fbc19c77-e130-4b43-bbdc-e97f1095ec04</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <roomenter type="script">
    </roomenter>
    <start type="script">
      game.turns = 0
      game.minutes = 0
      game.hours = 12
    </start>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <turnscript>
    <enabled />
    <script><![CDATA[
      game.turns = game.turns + 1
      game.minutes = game.minutes + 12
      if (game.minutes = 60) {
        game.hours = game.hours + 1
        game.minutes = 0
      }
      if (game.hours = 13) {
        game.hours = 1
      }
      msg ("Time: {game.hours}:{if game.minutes<10:0}{game.minutes}")
    ]]></script>
  </turnscript>
</asl>

VARIABLES: the two types

A 'Variable' VARIABLE is a local/temporary VARIABLE that exists only within its scripting (its 'scope') and is destroyed upon the scripting ending, and thus it can't be used outside of its scripting (its 'scope', if tried to use/reference the Variable outside of its scripting, it's an 'out of scope' ERROR, as the Variable actually doesn't exist outside of its scripting), which is what being 'local' means.

examples:

x = 50
hour = 11
handled = true
color = "red"
weapon = katana // the 'katana' has to be an actual existing Object

see how these 'Variable' VARIABLES have no ownership, they belong to nothing, they're stand-alone VARIABLES. Who's/What's 'x' ? No one's / Nothing's. Who's/What's 'hour' ? No one's / Nothing's. Who's/What's 'handled' ? No one's / Nothing's. Who's/What's 'color' ? No one's / Nothing's. Who's/What's 'weapon' ? No one's / Nothing's.


An 'Attribute' VARIABLE is a global/permanent VARIABLE, as it is a 'property/trait/characteristic/attribute/data' of an Object, so long as the Object exists, of course. Thus, it can be used/referenced anywhere, its 'scope' is global. An 'Attribute' VARIABLE is never destroyed, unless its Object is destroyed.

for example of the concept, myself:

// 'HK' has to be an actual existing Person, of course (which I am an actual existing person, lol):
HK.sex = "male"
HK.dead = false
HK.torso = shirt // the 'shirt' has to be an actual article of clothing, which it is, lol
HK.number_of_eyes = 2

this is data/properties/traits/characteristics of me, a real person:

Who's 'sex' ? MINE!
Who's '(not) dead' ? MINE!
Who's 'torso' ? MINE!
Who's 'number of eyes' ? MINE!

these 'Attribute' VARIABLES are specific to ME and only ME, and thus they can be used/referenced anywhere (so long as HK exists):

hey, you're wearing a shirt, and so is HK wearing a shirt, thus, you both matchingly are wearing shirts! (see below)

//  'Joe', 'HK', and 'shirt' are (aka, must be) all existing Objects:
Joe.torso = shirt
HK.torso = shirt

if (Joe.torso = shirt and HK.torso = shirt) {
  msg ("Joe and HK are both wearing a shirt!")
} else if (Joe.torso = shirt) {
  msg ("Joe is wearing a shirt, but HK is not wearing a shirt")
} else if (HK.torso = shirt) {
  msg ("HK is wearing a shirt, but Joe is not wearing a shirt")
} else {
  msg ("Neither Joe nor HK are wearing shirts")
}

now... the big super hard coding/logic question... for programmers/logicians/philosophers:

Are HK and Joe wearing the exact same shirt, or do they each have (and are wearing) their own (identical) shirts ?


game.turns = game.turns + 1
if ((game.turns%5) = 0) {
  msg ("Five turns just passed. This turn is divisible by 5.")
}

@HK

>Are HK and Joe wearing the exact same shirt, or do they each have (and are wearing) their own (identical) shirts ?

Error running script: Error compiling expression 'ListCombine(baselist, verbs)': FunctionCallElement: Could find not function 'ListCombine(Object, QuestList`1)'

Error running script: Error compiling expression 'ListCombine(baselist, verbs)': FunctionCallElement: Could find not function 'ListCombine(Object, QuestList`1)'


At least I did type in correctly 'shirt/shirts' and not.... 'skirt / skirts', laughs

care to explain your 'errors', ??? Which is it (wearing the exact same shirt, or wearing two identical separate shirts) and what's your reasoning/rationale ???

I myself am not sure which it is... just interested/curious to get people's thoughts on it, so I can get possible insight on ways of thinking about this towards a choice and the reasoning/rtionale behind it, hehe.


@HK

InvisiClue:

[ The same object is in more than one place. Quest no likey. ]


oh, you're going with the physics (newtonian physics / non-quantum physics) route, laughs.

But, quest in fact doesn't mind it at all, and works perfectly with it being done, grins.

this is a really advanced philosophical question... I should go to a philosophy class/professor and ask them this question!

what is the actual nature of a 'pointer/reference' in terms of its concept, which is what my philosophy-TE (thought experiement) question is asking ???


@HK

Whoa!

I was WRONG!

RH and HK are both wearing a shirt!

See the code
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Every Five Turns">
    <gameid>fbc19c77-e130-4b43-bbdc-e97f1095ec04</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <roomenter type="script">
    </roomenter>
    <start type="script">
      game.turns = 0
      game.minutes = 0
      game.hours = 12
    </start>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <enter type="script">
      RH.torso = shirt
      HK.torso = shirt
      if (RH.torso = shirt and HK.torso = shirt) {
        msg ("RH and HK are both wearing a shirt!")
      }
      else if (RH.torso = shirt) {
        msg ("RH is wearing a shirt, but HK is not wearing a shirt")
      }
      else if (HK.torso = shirt) {
        msg ("HK is wearing a shirt, but RH is not wearing a shirt")
      }
      else {
        msg ("Neither RH nor HK are wearing shirts")
      }
    </enter>
    <beforeenter type="script">
    </beforeenter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="RH">
      <inherit name="editor_object" />
    </object>
    <object name="HK">
      <inherit name="editor_room" />
    </object>
  </object>
  <turnscript>
    <enabled />
    <script><![CDATA[
      game.turns = game.turns + 1
      if ((game.turns%5) = 0) {
        msg ("Five turns just passed. This turn is divisible by 5.")
      }
      game.minutes = game.minutes + 1
      if (game.minutes = 60) {
        game.minutes = 0
      }
      game.hours = game.turns % 5
      if (game.hours = 13) {
        game.hours = 1
      }
      msg ("Time: {game.hours}:{if game.minutes<10:0}{game.minutes}")
    ]]></script>
  </turnscript>
  <object name="shirt">
    <inherit name="editor_object" />
  </object>
</asl>

Hey! That's cheating!!!

The shirt isn't really there (on RH or HK), is it?

It's like a one-object list, isn't it???


its a 'pointer/reference', but what is the nature of its concept ?

(ALL VARIABLES, in math and programming alike, are in fact, pointers/references)


(just edited this into my previous post -- probably didn't see it, so reposting it here too)

this is a really advanced philosophical question... I should go to a philosophy class/professor and ask them this question!

what is the actual nature of a 'pointer/reference' in terms of its concept, which is what my philosophy-TE (thought experiement) question is asking ???


I guess technically, since you're never doing two actions/operations at the same time, as I think that's impossible (aside from using multi-threads, though I don't think that'd technically be doing two actions/operations at the same time, as they're separate threads), the 'shirt' is being grabbed-and-used by one, and then it's grabbed-and-used by the other... hmm....

though, it's still interesting to think about whether its the exact same shirt being worn by both or two identical separate shirts, regardless of whether technically it's being 'musical chair / kid-grabbing, shared' or not.


Oh, so you do want a clock that says the minute is "105".

I just read that. Of course, I'm just saying that because NO ONE ANSWERED MY QUESTIONS.
(Except K.V. Thanks for that!)


@Enpherdaen Hard to spell name.
Just type:

if (expression) game.minute >= 60
  game.minute = 0

to set it back.
(Also, since time is an object, you'd have to adjust the code.)

Of course, your fantasy land apparently isn't like that, but I still think you should know.


yes, the 'Time.minutes' will be multiples of 60:

0 mins, 60 mins, 120 mins, 180 mins, 240 mins, 300 mins, 360 mins, 420 mins, 480 mins, 540 mins, 600 mins, etc
0 hrs, 1 hr, 2 hrs, 3 hrs, 4 hrs, 5 hrs, 6 hrs, 7 hrs, 8 hrs, 9 hrs, 10 hrs, etc

this is obviously not 'clock minute time', but it is 'minute quantity'

every 5 real/actual seconds, an in-game 'hr (+60 minutes) of time' passes


@ jmnevil54

Where is the 105 coming from, jmnevil54?


PS

Ha! I can post again!

(I got cut off for a while there. (Apparently, you can't post 1,000 posts per hour! Bwahahahahaha!)


A little off topic; but I notice that in a few games I've looked at, and in example code on the forum, using SetTurnTimeout to do something repeatedly seems to include multiple copies of the code. Always using the SetTurnTimeout (turns) { code } version of the statement.

I find it more elegant to use something like:

game.somescript => {
  // do stuff here
  if (condition_to_keep_going) {
    SetTurnTimeout (5, game.somescript)
  }
}
game.somescript

Not perfect, but it just seems more readable to me. Is that just my brain being weird?


Ughhh I hate complciated mathimatical scripting. That's why I'm doing it the easy way by using an object for time. Lol


I tried this out, but I think it won't work because I improperly coded "greater than". Also i don't know how to write in the player's current health so I just wrote "health".

SetTurnTimeout (5) {
  set (Time, "minutes", Time.minutes + 60)
  msg (Time.minutes)
}
if (Time.minutes = < 1259) {
  if (not IsSwitchedOn(Camp Fire)) {
    SetTurnTimeout (1) {
      DecreaseHealth (5)
    }
    msg ("Your health is now at" health "percent.")
  }
}
if (HasAttribute(player, "\"craft campfire\"")) {
  CloneObjectAndMove (Camp Fire, player)
}

Tell me how to do this properly.


(filler for getting edited post, updated/posted)


try to remember (me too, I have a hard time too, as I'm not using quest that much now due to school work demands):

its the greater/lesser than symbol FIRST (on the left) and then (on the right) it's the equal sign, (and to be safe, have no space between them, I've not tried if quest can handle a space between them or not, so again, to be safe: NO space between them):

try to remember to write/type it as you say it:

"GREATER THAN or equal to"
"LESSER THAN or equal to"
(first/left)..............(then/right)

<=
>=

so, your code fixed up:

// you need to add/create a 'Time' Object
// you need to add/create a 'minutes' Integer Attribute with it's initial Value set as '0 (zero)',  on/for your 'Time' Object

// I don't know how the 'SetTurnTimeout' works, so if you got mistakes with its usage, I wouldn't know and thus won't have it fixed up below

// You have to add/create a 'craft campfire' Attribute on/for your 'player' Player Object. (I presume it is a Boolean Attribute, so you can toggle it on/off via another scripting location/time in your game? It doesn't have to be a Boolean Attribute though, as any Attribute Type will work, barring whatever your game design is, anyways)

SetTurnTimeout (5) {
  set (Time, "minutes", Time.minutes + 60)
  msg (Time.minutes)
}
if (Time.minutes <= 1259) { // you could just do this too (less operations: more efficient): if (Time.minutes < 1300) {
  if (not IsSwitchedOn(Camp Fire)) {
    SetTurnTimeout (1) {
      DecreaseHealth (5)
    }
    msg ("Your health is now at " + player.health + " percent.")
  }
}
if (HasAttribute(player, "craft campfire")) {
  CloneObjectAndMove (Camp Fire, player)
}

Thanks mate. By the way I already got the time and minutes and all that.


I got another problem, which si the fact that when the time goes up by 60 after 5 turns, it only does it once. I've told Quest to add the value to Time.minutes, but it only does it after the first interval of 5. How do I get it to do it every interval?


(filler for getting edited post, updated/posted)


I guess the 'SetTurnTimeout' is only a one time thing (keep track/count of turns until it hits the specified amount of turns, which it then does its scripting/contents, and then it terminates/ends/finishes, and hence is only a one time event).

Thus you got to use something that isn't:

Turnscripts, Timers, the special 'changed' Script Attribute, the 'while' Function (with a counter), the 'for' Function (with a counter), or looping/recursion (with a counter).


I think the other users can probably help you better though, so wait for them, as I've never worked with the 'SetTurnTimeout' and don't know how it works.


One other possibility:

your 'SetTurnTimeout (1)' for your DecreaseHealth (5) change, could be over-riding your 'SetTurnTimeout (5)' for your +60 minutes change.


This script seems to run fine:

Hello! (I'm back online!)


This script seems to run fine (although I don't like the guy who posted it): http://textadventures.co.uk/forum/quest/topic/8rgyroemuk2llqfnydk-iq/increasing-the-value-of-an-attribute#5b0491a1-3581-425c-b873-f13af4033acf


Here's it's turnscript:

<turnscript>
    <enabled />
    <script><![CDATA[
      game.turns = game.turns + 1
      game.minutes = game.minutes + 12
      if (game.minutes = 60) {
        game.hours = game.hours + 1
        game.minutes = 0
      }
      if (game.hours = 13) {
        game.hours = 1
      }
      msg ("Time: {game.hours}:{if game.minutes<10:0}{game.minutes}")
    ]]></script>
  </turnscript>

You'd only need to substitute Time for game (I think).


Here's the output:


Every Five Turns

You are in a room.

> z
Time passes.
Time: 12:12

> z
Time passes.
Time: 12:24

> z
Time passes.
Time: 12:36

> z
Time passes.
Time: 12:48

> z
Time passes.
Time: 1:00

> z
Time passes.
Time: 1:12

> z
Time passes.
Time: 1:24

> z
Time passes.
Time: 1:36

> z
Time passes.
Time: 1:48

> z
Time passes.
Time: 2:00

> z
Time passes.
Time: 2:12


Hmm, there is a lot I do not understand about that and why they are there. Also if I use it, I A: Will not learn B: Will have difficulty making it work with what I already have C: Not be able to change things in it if I want/needed to.


(filler for getting edited post, updated/edited)
(again, filler for getting edited post, updated/edited)


<turnscript>
  <enabled />
  <script>
    <![CDATA[

      game.turns = game.turns + 1

      game.minutes = game.minutes + 12

      if (game.minutes = 60) {
        game.hours = game.hours + 1
        game.minutes = 0
      }

      if (game.hours = 13) {
        game.hours = 1
      }

      msg ("Time: {game.hours}:{if game.minutes<10:0}{game.minutes}")

    ]]>
  </script>
</turnscript>

1 hr = 60 minutes = 5 turns = 12 minutes per turn (60 minutes in 1 hr / 5 turns = 12 minutes per turn)


(for) each internal turn (any action: mouse click on a hypertext/button, or entering a typed-in input into the input command text box):

  1. game.turns = game.turns + 1

increase the 'game.turns' Integer Attribute ("counter") by 1

  1. game.minutes = game.minutes + 12

increase the 'game.minutes' Integer Attribute ("counter") by 12

  1. if (game.minutes = 60) {

check if 60 minutes (1 hr) have gone by (via: if game.minutes have increased to a current value of 60: aka, if 5 turns have passed), and if so, then:

game.hours = game.hours + 1

increase the 'game.hour' Integer Attribute ("counter") by 1 (as its been 60 minutes / 1 hr), and also:

game.minutes = 0

reset the 'game.minutes' Integer Attribute ("counter") back to '0 (zero)' as clock minutes time is: 0 to 59, (so '60' needs to be changed/reset to '0')

  1. if (game.hours = 13) {

check if the 'game.hours' Integer Attribute ("counter") current value is '13' (this scripting is keeping civilian time: 12 mid-night to 1 am to 11 am to 12 mid-day to 1 pm to 11 pm to 12 mid-night: 1-11 am, 12 mid-day, 1-11 pm, 12 mid-night, repeat), and if it is, then:

game.hours = 1

change the 'game.hours' Integer Attribute ("counter") from '13' to '1'

  1. msg ("Time: {game.hours}:{if game.minutes<10:0}{game.minutes}")

display the civilian clock time (hours:minutes): (1:00 to 12:59)


Wait, I got an idea. I can't tell you if it's stupid or not because I'm too novice to know.

SetTurnTimeout (5) {
  set (Time, "minutes", Time.minutes + 60)
  msg (Time.minutes)

What if I make this a function, and at the end of that function, I paste the function. So after 5 turns Time.minutes will increase by 60, then it will get to the function which is literally itself, and therefor repeat the process forever.


@HK

That was a NICE breakdown!


@Enpherdaen

It would be easier to add 12 to Time.minutes every turn.

image

image

image

image


Then, set up Time.minutes in your start script.

image


I'm adding a testing line to my turn script:

Time.minutes = Time.minutes + 12
msg ("Minutes: " + Time.minutes)

Press PLAY.


> z
Time passes.
Minutes: 12

> z
Time passes.
Minutes: 24

> z
Time passes.
Minutes: 36

> z
Time passes.
Minutes: 48

> z
Time passes.
Minutes: 60


@ E (Enpher... meh, you're 'E', lol):

yep, you can certainly do that! (this is called 'tail-recursion' looping: calling/doing the scripting again at the end of the scripting --- the 'end' doesn't have to be at the bottom though. I used to call it 'tail-end recursion' but that's not the correct term, lol. I still don't see/understand the difference between them... meh. Your tail and butt are one and the same, as both are referring to the opposite side of your head and neck. That's what it means to be a chordata organism, you got a single bar for your frame, your spine, which protects your central nerve frame from your brain to your opposite end, your butt/tail. One end of this single bar frame is the organism's head/neck/brain and the other side is the organism's butt/tail. You ingest through your mouth/head and excrete the waste/by-products out your anus-big-intestine/urethra-small-intestine at your bottom: backside's butt/tail and front-side's genitilia, But whatever, I digress, lol)

HOWEVER, you do NOT want it to be forever, as that causes a crash, lol. This is called an 'infinite loop', which will crash quest.

You need a way of stopping it from being forever, there's many ways of doing this, as well as depending on the design/method of doing your looping as well.

one example:

<game name="example_game">
  <attr name="start" type="script">
    example_function
  </attr>
</game>

<object name="Time">
  <attr name="minutes" type="int">0</attr>
</object>

<function name="example_function">
  SetTurnTimeout (5) {
    set (Time, "minutes", Time.minutes + 60)
    msg (Time.minutes)
  }
  ask ("Continue?") {
    if (result) {
      example_function
    }
  }
</function>

this requires your input, vis using the built-in 'ask' pop up 'yes:true/no:false' window menu, which determines if it continues (does the scripting again: loops) or not


you can do the same thing with a Script Attribute, instead of a Function, which is really better, as you can organize your systems better as it (Script Attributes) uses Objects, which are much more powerful/useful than Functions, an example:

(Also, a Script Attribute can do the same argument/parameter and/or returning a value as a Function can, via using 'Delegates' with your Script Attribute, so really using Script Attributes are completely better than Functions, unless you're doing something really simple, as that would be "overkill", aka "using a nuke to kill a fly". Though, learning how Delegates can be a bit difficult at first, as I myself didn't understand them for a long time too, I wish I had learned them earlier, sighs. As I now hardly ever use Functions anymore, lol)

<game name="example_game">
  <attr name="start" type="script">
    do (Time, "example_script_attribute")
  </attr>
</game>

<object name="Time">
  <attr name="minutes" type="int">0</attr>
  <attr name="example_script_attribute" type="script">
    SetTurnTimeout (5) {
      set (Time, "minutes", Time.minutes + 60)
      msg (Time.minutes)
    }
    ask ("Continue?") {
      if (result) {
        do (Time, "example_script_attribute")
      }
    }
  </attr>
</object>

K.V. I never thought of that, sounds like a good idea.

Hegemonkhan I actually figured it'd crash or bug out, which is why I asked the question. How do you tell Quest when to stop it?

Somebody really needs to tell me how to tag people.


just edited in my previous post (sorry), showing one (of infinite --- bad pun --- not intended, lol) ways of preventing it from being "infinite looping", so if you don't mind, take a look at my previous post again, if you want to see a way of doing it.

if you need help with ways of doing it, I can help, showing you more ways of doing it, and you can decide which you like best/understand-most/best-for-your-game-design/etc


H.K that is a great breakdown.


edited my previous post (the one with the example of preventing endless/infinite loop) again (just fixed up the code a bit better), one last look at it (sorry again).


... hegemonkhan, I think that's not what he means.

I think he means:

Time.example_script => {
  set (Time, "minutes", Time.minutes + 60)
  msg (Time.minutes)
  SetTurnTimeout (5, Time.example_script)
}
do (Time, "example_script")

(off the top of my head, so I may have errors there)
Once called, the function will then be called every five turns until the game ends. It keeps going forever, but that is not a problem, because the core code is allowed to run in between.

(and if you want to stop the clock for some reason, you can then do Time.example_script => {})


@ Enpherdaen
You can't really tag anyone (as far as I know). Some folks use@, but it doesn't really do anything.


Also, look at the code on this post again:

http://textadventures.co.uk/forum/quest/topic/8rgyroemuk2llqfnydk-iq/increasing-the-value-of-an-attribute#ae609987-144e-48e8-9986-a37eb894d15d

It's doing the same thing, but it's keeping track of hours along with the minutes.


Creating a new object when the sole purpose is setting attributes on it accomplishes the following:

There is one extra object with X amount of attributes, and the game has X less attributes.

Neither way is any better than the other, as far as I've been able to discern.

I set up objects to set CSS or Base64 attributes on. Then I nest those objects just above the walkthroughs in Code View. That way, all the long text is at the bottom of the file. So, I'm not saying you're doing it wrong. I'm just pointing out why I went with game.minutes and game.hours. (It's just easier.)


Also, scrolling through all the philosophy above, I caught sight of this error message:

Error running script: Error compiling expression 'ListCombine(baselist, verbs)': FunctionCallElement: Could find not function 'ListCombine(Object, QuestList`1)'

Did RH try to put a shirt on his displayverbs instead of his torso?


ah, oops, if that is what 'E' meant... my bad for interpreting/assuming that was what he meant.

@ E:

use mrangel's code then, if that's what you wanted.


@ mrangel's comment in his post:

what would... KV's 'displayverbs' be (what are KV's 'displayverbs ?) exactly as well, lol.... maybe HK doesn't want to know, lol


@HK

Did RH try to put a shirt on his displayverbs instead of his torso?

He tried to start a game with Object: shirt in Object: RH and Object: HK! (He entered that in Code View, then pressed PLAY. (RH is not the sharpest tool in the shed.))


if anyone wants a challenge, you can try to understand how this convoluted design works (this was back when I myself was trying to learn basic time coding):

http://textadventures.co.uk/forum/samples/topic/4162/countdown-timer-code (it counts down from 60 hrs, 1 second at a time: 60 hrs : 00 mins : 00 secs to 00 hrs : 00 mins : 00 secs)

have fun trying to figure it out! :D


Right, seperate issue: When Time.minute is equal to or greater than 1260, my health should start going down by 5 every turn and my health should be displayed. However it is not being displayed and I'm not sure if it is even depleting. I also don't know how to make the depletion happen with every turn after 1260, rather than once.

if (Time.minutes <= 1260) {
  SetTurnTimeout (1) {
    DecreaseHealth (5)
  }
  msg ("Your health is now at " + player.health + " percent.")
}

Also now that I got time to work properly, what would be the simplest way for the game to display the amount of minutes as civilian time? Ex: 540 = 9 AM


(filler for getting my edited post, updated/posted)


can you post your code? (so we can see what is going on, and thus how to fix it up for you. it's easier for us to just directly to see the code than you trying to explain it and we trying to understand it via typing/reading posts about it, lol)


you could also just try mrangel's code... as there's likely some issues with your code design that doesn't work, and as I'm not familiar with how the 'SetTurnTimeout' works, I'm not really sure why it's not working and nor how to fix it up so it does work. Maybe someone else can help you with why it's not working and how to get it working.


the 'am/pm' handling will require its own extra coding, easiest would be to implement it with the per hour time change (when/if game.minutes = 60) part of your scripting/design, for an example:

<game name="example_game">
  <attr name="turns" type="int">0</attr>
  <attr name="minutes" type="int">0</attr>
  <attr name="hours" type="int">0</attr>
  <attr name="am_or_pm" type="string">am</attr>
  <attr name="civilian_clock_time" type="string">Time: 00:00 am</attr>
</game>

<turnscript>
  <enabled />
  <script>
    <![CDATA[

      game.turns = game.turns + 1

      game.minutes = game.minutes + 12

      if (game.minutes = 60) {

        game.hours = game.hours + 1
        game.minutes = 0

        if (game.hours = 12) {
          if (game.am_or_pm = "am") {
            game.am_or_pm = "pm"
          } else { // else if (game.am_or_pm = "pm") {
            game.am_or_pm = "am"
          }
        } else if (game.hours = 13) {
          game.hours = 1
        }

      } // ending tag of 'if (game.minutes = 60)' tag block

      game.civilian_clock_time = "Time: {game.hours}:{if game.minutes<10:0}{game.minutes} {game.am_or_pm}"

      msg (game.civilian_clock_time)

    ]]>
  </script>
</turnscript>

wow.... in editing this post just now, I just now realized that it's inefficient to have the check for changing the hrs from 13 to 1, being done every internal turn (so I put/have it only happening when the minutes hit 60: only checks when each hour has passed)


H.K does that mean I'll have to strip my time related code entirely?


probably not, but maybe... it depends on understanding what is going on, how it works, and how it can be fixed (and whether/if it can be fixed or not). I don't understand it, but hopefully someone else can help with your code, in whether it can be fixed up or not (having to use another/different design instead).

(edited my previous post: added more content and noticed and fixed some stuff up with it, so if want, take a look at it)


One small thing I have trouble understanding:
game.turns = game.turns + 1
Does that have to do with time? It seems like it is there so the scripter can refer to a specific turn if he needed to. Would that be why?


no, that has nothing to do with any of the clock time stuff.

it's just there as usually people like to see their game turns (I don't think there's any way of directly displaying and/or of accessing the internal turns, we indirectly use the Turnscript instead, so that's why most people create a 'turns' Integer Attribute, so they can display it for people to see the 'turn' they're on and/or how many turns have passed/been-done, lol. Also, they may want to have code that uses their 'turn' Integer as well, such as maybe random/specific events happening on certain/specific turns and/or intervals of turns), for such types of games that use game turns, for example:

<game name="example_game">
  <attr name="turns" type="int">0</attr>
  <attr name="minutes" type="int">0</attr>
  <attr name="hours" type="int">0</attr>
  <attr name="am_or_pm" type="string">am</attr>
  <attr name="civilian_clock_time" type="string">Time: 00:00 am</attr>
</game>

<turnscript>
  <enabled />
  <script>
    <![CDATA[

      game.turns = game.turns + 1

      game.minutes = game.minutes + 12

      if (game.minutes = 60) {

        game.hours = game.hours + 1
        game.minutes = 0

        if (game.hours = 12) {
          if (game.am_or_pm = "am") {
            game.am_or_pm = "pm"
          } else { // else if (game.am_or_pm = "pm") {
            game.am_or_pm = "am"
          }
        } else if (game.hours = 13) {
          game.hours = 1
        }

      } // ending tag of 'if (game.minutes = 60)' tag block

      game.civilian_clock_time = "Time: {game.hours}:{if game.minutes<10:0}{game.minutes} {game.am_or_pm}"

      msg ("Turns: {game.turns}")
      msg (game.civilian_clock_time)

    ]]>
  </script>
</turnscript>

// example displayment:

Turns: 42
Time: 6:32 pm

you can completely remove all the 'game.turns' stuff, it has nothing to do with the clock time stuff

(some people use a 'turn' Integer Attribute as their base unit, instead of a 'second' Integer Attribute or instead of a 'minute' Integer Attribute as is used in the example code here, for time though, so you got to know what's going on before you remove it or not: make sure none of the time code is based upon the 'turns' Integer Attribute, before you remove it)


Doesn't Time.minutes reset to 0 every time it hits 60?


game.turns = 105 is 1260 minutes.


If I understand you correctly:

  • You want to increase the minutes by 60 every 5 turns (not increase the minutes by 12 every turn)
  • You want a Time object, with the attributes set on it
  • You want the player to lose 5% health every turn after passing the 1,260 minute mark
  • You want a clock displayed

Did I miss anything?


If not:

  1. Create a new game.
  2. Go to Code View
  3. Delete everything
  4. Copy and paste this entire code into it
  5. Press play
CLICK HERE FOR THE CODE (includes some of everyone's codes from this thread)
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Time.time">
    <gameid>6730414f-f6f3-4d2c-8b55-5db518b1308a</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <showhealth />
    <statusattributes type="stringdictionary">
      <item>
        <key>timeDisplay</key>
        <value></value>
      </item>
    </statusattributes>
    <displayTime type="string"></displayTime>
    <start type="script">
      Time.minutes = 0
      Time.hours = 12
      Time.am_or_pm = "am"
      Time.display = "12:00 am"
      game.timeDisplay = Time.display
      addMinutesFunction
    </start>
    <object name="Time">
      <inherit name="editor_object" />
    </object>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <turnscript name="hourTurnscript">
    <enabled />
    <script><![CDATA[
      if (Time.minutes = 60) {
        Time.hours = Time.hours + 1
        Time.minutes = 0
        if (Time.hours = 12) {
          if (Time.am_or_pm = "am") {
            Time.am_or_pm = "pm"
          }
          else {
            Time.am_or_pm = "am"
          }
        }
      }
      if (Time.hours = 13) {
        Time.hours = 1
      }
      Time.display = "" + Time.hours + ":" + ProcessText("{if Time.minutes<10:0}{Time.minutes}") + " " + Time.am_or_pm + ""
      game.timeDisplay = Time.display
      msg ("Time: {Time.hours}:{if Time.minutes<10:0}{Time.minutes} {Time.am_or_pm}")
    ]]></script>
  </turnscript>
  <turnscript name="killPlayer">
    <enabled />
    <script><![CDATA[
      if (game.turns >= 105) {
        player.health = player.health - 5
        msg ("You are dying")
        killFunction
        DisableTurnScript (killPlayer)
      }
    ]]></script>
  </turnscript>
  <turnscript name="turnCount">
    <enabled />
    <script>
      game.turns = game.turns + 1
    </script>
  </turnscript>
  <function name="addMinutesFunction">
    SetTurnTimeout (5) {
      msg ("TEST MESSAGE: ADDING 60 MINUTES")
      Time.minutes = Time.minutes + 60
      addMinutesFunction
    }
  </function>
  <function name="killFunction">
    SetTurnTimeout (1) {
      player.health = player.health - 5
      msg ("You are dying")
      killFunction
    }
  </function>
</asl>

This is how I would do it, if I wanted the same results you're after, with no complicated math involved:

CLICK HERE TO VIEW CODE
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Time.time">
    <gameid>6730414f-f6f3-4d2c-8b55-5db518b1308a</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <showhealth />
    <statusattributes type="stringdictionary">
      <item>
        <key>timeDisplay</key>
        <value>Time: !</value>
      </item>
    </statusattributes>
    <displayTime type="string"></displayTime>
    <start type="script">
      game.minutes = 0
      game.hours = 12
      game.am_or_pm = "am"
      game.timeDisplay = "12:00 am"
      game.turns = 0
    </start>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <turnscript name="hourTurnscript">
    <enabled />
    <script><![CDATA[
      game.minutes = game.minutes + 12
      if (game.minutes = 60) {
        game.hours = game.hours + 1
        game.minutes = 0
        if (game.hours = 12) {
          if (game.am_or_pm = "am") {
            game.am_or_pm = "pm"
          }
          else {
            game.am_or_pm = "am"
          }
        }
      }
      if (game.hours = 13) {
        game.hours = 1
      }
      game.timeDisplay = "" + game.hours + ":" + ProcessText("{if game.minutes<10:0}{game.minutes}") + " " + game.am_or_pm + ""
      msg ("Time: {game.timeDisplay}")
    ]]></script>
  </turnscript>
  <turnscript name="killPlayer">
    <enabled />
    <script><![CDATA[
      if (game.turns >= 105) {
        player.health = player.health - 5
        msg ("You are dying")
        killFunction
        DisableTurnScript (killPlayer)
      }
    ]]></script>
  </turnscript>
  <turnscript name="turnCount">
    <enabled />
    <script>
      game.turns = game.turns + 1
    </script>
  </turnscript>
  <function name="killFunction">
    SetTurnTimeout (1) {
      player.health = player.health - 5
      msg ("You are dying")
      killFunction
    }
  </function>
</asl>

timeTime_REVAMPED.aslx


To do it the way you're wanting to do it, you probably need functions that call SetTurnTimeout and call themselves at the end of the script.


  1. K.V 60 every 5 and 12 every 1 are both the same to me, but I guess 12 every 1 is more plausable.
  2. I don't "want" a time object, it just as of now seems simpler for me.
  3. Yes until 6 AM the next day (unless the player slept in a shelter and skipped to morning or stayed by a fire to keep warm).
  4. I'll probably have a clock found or made eventually so I suppose yes.

Cool.

You can right click on that link in by post from 10 minutes back, save as, then open it and check it out.

You can open it in the editor and check stuff out in the GUI, too.


PS

The time object is totally a good idea, but, if you want the time displayed in the status pane (like I've got it set up), it's way easier just to set it all up on the game. (I didn't mean anything by whatever I said whenever I referenced that. Sorry!)

The Time object is that spoon on The Matrix. There is no time object. (In fact, there is no time. It's an illusion, designed to imprison your mind. (Arrgh... Sorry! I hate it when I go in MATRIX-MODE!)

The Time object is like Dumbo's feather. You can really fly without it, but you THINK it makes you fly, so build your world game around it, rendering it important.


Alright, I'll see how it goes. By the way I don't need to call any functions, it's already on loop using the Time.minutes + 12 turn script.


That's not to say you can't keep the Time object and use it.

You'd just need to add a few lines of code here and there to pass the value to a status attribute (which is the attribute that passes the value to the display in the Status pane). I think only the player object and the game object can have a status attribute set up as default, but I may be wrong.


NOTE:

You're fooling around with one of the more complicated things. Even though it seems like it should just work easily, it doesn't; does it? (I gained respect for my digital clocks after I got time-keeping in Quest mostly figured out!)

Don't sweat it, though. You're doing great, and you've almost got it just like you want it!

Lots of people would have given up a long time ago, too!


By the way I don't need to call any functions, it's already on loop using the Time.minutes + 12 turn script.

Which part?

Killing the player?


The Pixie1 taught me to set up a different turn script and a different function for each different thing.

It seems excessive, but it is much easier to change things that way, and it's MUCH easier to decipher once you've finished the game and moved on.

FOOTNOTES --- FOOTNOTE 1:

The Pixie is the maintainer2 of Quest.

If The Pixie says a method is the best method, I may think The Pixie's wrong for a few minutes sometimes...

...but The Pixie's pretty smart. (It's hard to catch The Pixie slippin'.)


FOOTNOTE 2:

I believe 'maintainer' is the correct title...

If not, correct me, and I shall edit.


Thanks!

No I was referring to the function functioning (pun intended) for every turn, adding 12 minutes to Time.minute


"Also now that I got time to work properly, what would be the simplest way for the game to display the amount of minutes as civilian time? Ex: 540 = 9 AM (Enpheraen)"


// 540 = 9 am

// game.minutes = 540

civilian_clock_hour_integer_variable = (((game.minutes / 60) + 11) % 12) + 1 // (credit to 'mrangel' for this equation fix)

msg ("Time: " + civilian_clock_hour_integer_variable + " " + game.am_or_pm)


Thanks H.K, is that all of it? 1 line on code is really shocking. Also, do you mind explaining how exactly it works?


@HK!!!

>what would... KV's 'displayverbs' be (what are KV's 'displayverbs ?) exactly as well, lol.... maybe HK doesn't want to know, lol


You are on the forum.

You can see K.V. here.


(Just hover over the link to see my display verbs, HK! (Bwahahahaha!))


the 'best' method is what's best for you and/or others, unless you're working with something critical (life and death: for example: car/airplane/jet controls: you don't want any delays in the computer electronic response times, lol) where efficiency/speed matters and/or if working with something compact (literally physically very little space/room for computer parts/chips, thus you got to be really efficient, as you don't have lots of parts/chips as you just don't have the space/room for lots of parts/chips)

what that means is: organization/scale'ability/easy-edit'ability, read'ability/understand'ability (first time seeing it and/or coming back after a long time forgetting all of it), trouble-shooting, etc etc etc

your "developer time" is the most valuable resource, as it's your time, work, and money. Yes, your life matters, and you got a highly needed skill, so don't let others or yourself, rip yourself off. Your time/work/skill is a premium, never forget it!


Post removed due to my confusion at the time.

Click here to read a pointless message (if you can see this, that is).

I was confused at this point. I deleted what I posted here so it wouldn't confuse anyone else. (Ha-ha! I try to NOT throw monkey wrenches.)


Wow okay.


(filler for getting my edited post, updated/posted)


@ E:

the '%' is the 'modulus' operator/operation, which is just division, EXCEPT it finds/gets/returns the REMAINDER

https://en.wikipedia.org/wiki/Modulo_operation ('modulus' is usually used as its easier to say/remember, it's latin --- what science doesn't use latin --- lol, so it's some kind of grammer form of it, most likely: see link below)

https://en.wikipedia.org/wiki/Modulus


The reason why the '% (modulus)' operator/operation is so useful, is because:

the REMAINDER (of division) is very special, as it can be used for:

  1. cyclic
  2. (odd/even)-ness of a number
  3. factoring/divisible-ness of a number

  1. cyclic (repeating/limited sequences):

number systems: 0 to N digits (decimal/metric number system: base 10: 0 to 9 digits, binary/digital number system: base 2: 0 to 1 digits, hexidecimal number system: base 16: 0 to 9 to A::10 to F::15 digits, octal number system: base 8: 0 to 7 digits, viking/american/"imperial"/curvature/time unit/measurement system: base 12: 0 to 11 digits, etc etc etc)

time/dates: 0 to N digits (seconds/minutes: 0 to 59, civilian-hours/months-in-a-year: 0 to 11, military-hours: 0 to 23, days-in-a-week: 0 to 6, etc etc etc)

etc etc etc stuff

  1. (odd/even)-ness of a number

is 59 odd or even? ODD
is 88 odd or even? EVEN

  1. factoring/divisible-ness of a number

is 49 divisible by 7 ? / is '7' a factor of '49' ? ---> YES/TRUE
is 48 divisible by 7 ? / is '7' a factor of '48' ?---> NO/FALSE

is 63 divisible by 3 ? / is '3' a factor of '63' ? ---> YES/TRUE
is 62 divisible by 3? / is '3' a factor of '62' ? ---> NO/FALSE


how does it work?


Cyclic:

let's take a simple example of the (4) seasons (using a small number so it's easy/quick to show it):

4 quantity of digits: base 4 = 4^N: 0 to 3 digits:

N = 1, as we're just taking the seasons: 4^(N:1) = 4 seasons

// concept only (we'd have to use a Dictionary Attribute to actually literally do this, which is too much effort, as the point here is to explain the modulus, not Dictionary Attribute usage, lol):
0 = winter
1 = spring
2 = summer
3 = autumn

game.count = 0
// pretend this is an infinite loop:
game.season = (game.count) % 4
game.count = game.count + 1


// game.count = 0
game.season = (0) % 4 = (Q: 0, R: 0) = R: 0 = 0 = winter

// game.count = 1
game.season = (1) % 4 = (Q: 0, R: 1) = R: 1 = 1 = spring

// game.count = 2
game.season = (2) % 4 = (Q: 0, R: 2) = R: 2 = 2 = summer

// game.count = 3
game.season = (3) % 4 = (Q: 0, R: 3) = R: 3 = 3 = autumn

// game.count = 4
game.season = (4) % 4 = (Q: 1, R: 0) = R: 0 = 0 = winter

// game.count = 5
game.season = (5) % 4 = (Q: 1, R: 1) = R: 1 = 1 = spring

// game.count = 6
game.season = (6) % 4 = (Q: 1, R: 2) = R: 2 = 2 = summer

// game.count = 7
game.season = (7) % 4 = (Q: 1, R: 3) = R: 3 = 3 = autumn

// game.count = 8
game.season = (8) % 4 = (Q: 2, R: 0) = R: 0 = 0 = winter

// game.count = 9
game.season = (9) % 4 = (Q: 2, R: 1) = R: 1 = 1 = spring

you get the idea now....

this works for any: % VALUE


let's do clock time displayment of seconds-or-minutes (% 60), as this directly uses the '0 to 59' (no fancy math equation nor additional code work to adjust it to the desired number, lol) to see that it does:

game.clock_seconds = game.count % 60

// game.count = 0
game.clock_seconds = (0) % 60 = (Q: 0, R: 0) = R: 0 = 0

... (yada yada yada) ....

// game.count = 59
game.clock_seconds = (59) % 60 = (Q: 0, R: 59) = R: 59 = 59

// game.count = 60
game.clock_seconds = (60) % 60 = (Q: 1, R: 0) = R: 0 = 0

// game.count = 61
game.clock_seconds = (61) % 60 = (Q: 1, R: 1) = R: 1 = 1

... (yada yada yada) ....

// game.count = 119
game.clock_seconds = (119) % 60 = 119 / 60 = Q: 1 ---> 1 * 60 = 60 ---> 119 - 60 = R: 59 = 59

// game.count = 120
game.clock_seconds = (120) % 60 = (Q: 2, R: 0) = R: 0 = 0

// game.count = 121
game.clock_seconds = (121) % 60 = 121 / 60 = Q: 2 ---> 2 * 60 = 120 ---> 121 - 120 = R: 1 = 1


// game.count = 579
game.clock_seconds = (579) % 60 = 579 / 60 = Q: 9 ---> 9 * 60 = 540 ---> 579 - 540 = R: 29 = 29


(Odd/Even)-ness of a number:

// anything divisible by 2 (aka, no remainder), is an even number:

// game.number = WHATEVER_INTEGER_VALUE

// (an 'integer' number is a non-decimal number: ..., -999, -1, 0, 1, 999, ....)
// (a 'double/float/floating-point/decimal' number is a decimal number: ..., -987.123, -1.546, 0.0, 13.8, 912.87, ...)
// (not used in programming or at least not usually anyways, lol: a 'whole' number is a positive number: not negative and not 0, I think, lol)

if (game.number % 2 = 0) {
  msg ("The number " + game.number + " is even")
} else { // ***
  msg ("The number " + game.number + " is odd")
}

// ***
// this is not needed (as the 'else' is all we need), but this is to just show you mathematically (shown as code of course, as we're coding here, lol) what's happening (as whenever you divide a number by 2, you either get 0 or 1 for the remainder) for the 'else' condition:
// else if (game.number % 2 = 1) {

// in other words, we could do this code design instead:

if (game.number % 2 = 1) {
  msg ("The number " + game.number + " is odd")
} else {
  msg ("The number " + game.number + " is even")
}

factoring/divisible-ness of a number:

if (game.number % 1 = 0) { // LOL, as every number is of course divisible by 1, LOL
  msg ("The number " + game.number + " is divisible by 1, or to say it another way, 1 is a factor of " + game.number)
} else if (game.number % 2 = 0) {
  msg ("The number " + game.number + " is divisible by 2, or to say it another way, 2 is a factor of " + game.number)
} else if (game.number % 3 = 0) {
  msg ("The number " + game.number + " is divisible by 3, or to say it another way, 3 is a factor of " + game.number)
} else if (game.number % 4 = 0) {
  msg ("The number " + game.number + " is divisible by 4, or to say it another way, 4 is a factor of " + game.number)
} else if (game.number % 5 = 0) {
  msg ("The number " + game.number + " is divisible by 5, or to say it another way, 5 is a factor of " + game.number)
} else if (game.number % 6 = 0) {
  msg ("The number " + game.number + " is divisible by 6, or to say it another way, 6 is a factor of " + game.number)
} else if (game.number % 7 = 0) {
  msg ("The number " + game.number + " is divisible by 7, or to say it another way, 7 is a factor of " + game.number)
} else if (game.number % 8 = 0) {
  msg ("The number " + game.number + " is divisible by 8, or to say it another way, 8 is a factor of " + game.number)
}
// and on and on, you get the idea.....
else if (game.number % game.number = 0) { // LOL, as every number is divisible by itself, as well, lol
  msg ("The number " + game.number + " is divisible by " + game.number + ", or to say it another way, " + game.number + " is a factor of " + game.number)
}

H.K No thanks, I had enough compliciated stuff in High School. lol


well, just look at the coding of how its 3 ways are done, and a little bit of work to understand it (or just ask us for help) -- so you can use it, without getting into the math details of how it works (it does work, so who cares how it works, am I right or am I right, hehe-lol)


to re-hash cyclic:

VARIABLE_B = VARIABLE_A_or_B % VALUE

the 'VALUE' is the range/sequence of digits: 0 to VALUE-1

% 1: 0,0,0,... // I wonder if this works, or if there's some weird/fascinating quirk that prevents it from working... I should try/test it!
% 2: 0,1,0,1,0,1,0,1,...
% 3: 0,1,2,0,1,2,0,1,2,....
% 4: 0,1,2,3,0,1,2,3,0,1,2,3,....
% 5: 0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,....
% 6: 0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5....
% 7: 0,1,2,3,4,5,6,0,1,2,3,4,5,6,0,1,2,3,4,5,6,....
% 8: 0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,....
... you get the idea...
% 12: 0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,11,...
... you get the idea...

seconds/minutes have '60' units/digits, so you do: % 60 ---> 0 to 59
civilian hours has '12' units/digits, so you do: % 12 ----> 0 to 11
military hours has '24' units/digits, so you do: % 24 ----> 0 to 23
etc etc etc

you never change the % VALUE, it must be matched up to what you're using it for (aka, military time is based on 24 hours, so you use '24' for your modulus value: % 24), as it won't work if you change it, for example, if you do for seconds/minutes: % 61, it's going to screw everything up majorly wrongly! What you can do: is adjust its equation/expression that you use it in or you do 'if' checks to adjust the value to what it should be, the common reason for using either of these methods, is that you don't want to use/have '0' as the min (wanting to use/have '1' as the min) and you don't want to use/have 'VALUE-1' as the max (wanting to use/have 'VALUE' as the max).

Hmm, fascinating.


Health still won't deplete and the message will not show up. Any ideas why?

if (Time.minutes <= 1260) {
  SetTurnTimeout (1) {
    DecreaseHealth (5)
  }
  msg ("Your health is now at " + player.health + " percent.")
}

Well, it should print until the turn count is higher than 21, since you have Time.minutes <= 1260, as long as that script is called every turn (which I have no idea whether it is or not).


Is it in a turn script? If yes, is the turn script enabled?

If it IS in a turn script, the SetTurnTimeout seems pointless.

IF this script is called every turn, you could just do this:

if (Time.minutes >= 1260) { // NOTE: Changed to GREATER THAN or EQUAL TO
    msg ("TESTING MESSAGE: minutes are greater than or equal to 1260. Decreasing health...")
    DecreaseHealth (5)
    msg ("Your health is now at " + player.health + " percent.")
}

Again, there are numerous ways to script these things, and numerous ways to piece all of the possible scripts together.

If you were to post your entire code here, we could see how everything works together. We're simply guessing, otherwise.

BIG QUESTION

Is there something in your game's code that changes Time.minutes to 0 every time Time.minutes = 60, so the hour changes???

If the answer is yes, Time.minutes will never exceed 60, so checking for it to be 1260 is a waste of time. (Again, I don't know how you have this part scripted.)


This script as posted:

if (Time.minutes <= 1260) {
  SetTurnTimeout (1) {
    DecreaseHealth (5)
  }
  msg ("Your health is now at " + player.health + " percent.")
}

Its behaviour should be: If the minutes are less than 1260, then leave a note telling Quest to decrease the player's health at the end of the next turn; and display the current health.
Does the message not show up at all? Is the script that contains this being reached?

If I was having a problem like this, I would add a line to make it easier to track what's going on. Something like:

msg ("DEBUG: got here, and minutes is "+Time.minutes)
if (Time.minutes <= 1260) {
  SetTurnTimeout (1) {
    DecreaseHealth (5)
  }
  msg ("Your health is now at " + player.health + " percent.")
}

If the DEBUG message displays a number of minutes greater than 1260, you know why you weren't being damaged.
If the debug message doesn't display at all, then you know the problem isn't in this bit of code because this code is never being run.


Play this and see if it does what you want:

Play example online (if it doesn't freeze up before you make it to 6 am!).

Download the example game file (includes super-sweet walkthrough).

Play begins at 9 am.

At 6 am, you will lose 5% health at every turn until you are dead, dead, dead.


Click here to view the one start script that sets it all up.

NOTE: I tried to make this keep time and kill the player the way Enpherdaen has described.


Start Script (this creates the Time object and ALL turn scripts involving time, health, status attributes, and the player dying)

game.showhealth = true
game.pov.health = 100
game.pov.changedhealth => {
  if (game.pov.health > 100) {
    game.pov.health = 100
  }
  else if (game.pov.health = 0) {
    if (HasScript(game, "onhealthzero")) {
      do (game, "onhealthzero")
    }
  }
  else if (game.pov.health < 0) {
    game.pov.health = 0
    // changedhealth will be called again so the onhealthzero script will run
  }
}
game.povstatusattributes = NewStringDictionary()
dictionary add (game.povstatusattributes, "health", "Health: !")
JS.uiShow ("div#commandPane")
JS.setCommands ("Wait")
create ("Time")
Time.realMinutes = 0
Time.minutes = 0
Time.hours = 9
Time.am_or_pm = "am"
Time.display = "9:00 am"
game.statusattributes = NewStringDictionary()
dictionary add (game.statusattributes, "timeDisplay", "Time: !")
game.timeDisplay = Time.display
create turnscript ("myTurnScript")
myTurnScript.script => {
  Time.realMinutes = Time.realMinutes + 12
  Time.minutes = Time.minutes + 12
  if (Time.minutes = 60) {
    Time.hours = Time.hours + 1
    Time.minutes = 0
    if (Time.hours = 12) {
      if (Time.am_or_pm = "am") {
        Time.am_or_pm = "pm"
      }
      else {
        Time.am_or_pm = "am"
      }
    }
  }
  if (Time.hours = 13) {
    Time.hours = 1
  }
  Time.display = "" + Time.hours + ":" + ProcessText("{if Time.minutes<10:0}{Time.minutes}") + " " + Time.am_or_pm + ""
  game.timeDisplay = Time.display
  // msg ("Time: {Time.hours}:{if Time.minutes<10:0}{Time.minutes} {Time.am_or_pm}")
  if (Time.realMinutes >= 1260) {
    player.health = player.health - 5
    msg ("Your health is now at " + player.health + " percent.")
  }
}
EnableTurnScript (myTurnScript)
game.onhealthzero => {
  msg ("You have died.")
  finish
}

  1. player.health does not equal Quest's built in health.
    You will need to ask someone how to message it.
    Didn't you check/click the health thingy?

If you want player.health, you will need to make it an attribute yourself.

Then you need to make a dictionary.
My own looks like this.
//////

player.statusattributes = NewStringDictionary()
dictionary add (player.statusattributes, "hitpoints", "Hit points: !")
dictionary add (player.statusattributes, "ammo", "Spare ammo: !")
dictionary add (player.statusattributes, "equippedname", "Weapon: !")
dictionary add (player.statusattributes, "ammonote", "Ammo: !")
dictionary add (player.statusattributes, "level", "level: !")
dictionary add (player.statusattributes, "exp", "exp: !")
dictionary add (player.statusattributes, "potion", "Potions: !")
dictionary add (player.statusattributes, "hyper_potion", "Hyper Potions: !")

Here's a screenshot of it. Imgur.
https://i.imgur.com/c2BzHxv.png
And it just shows up in the status pane.

  1. @K.V. I think he made his own code. It flips every so often using a turnscipt. I can't figure out the rest, it's gobble-ty-gook to me!

@ jmnevil54

player.health does not equal Quest's built in health

Yuh-huh, jmnevil54.

If you enable Health in the features:

image


Then, to change what it shows in the pane:

dictionary remove(game.povstatusattributes, "health")
dictionary add (game.povstatusattributes, "health", "THIS IS YOUR HEALTH: !")


@ jmnevil54

You can skip enabling Health in the editor, and just put this in your start script (edited):

game.showhealth = true
game.pov.health = 100
game.pov.changedhealth => {
  if (game.pov.health > 100) {
    game.pov.health = 100
  }
  else if (game.pov.health = 0) {
    if (HasScript(game, "onhealthzero")) {
      do (game, "onhealthzero")
    }
  }
  else if (game.pov.health < 0) {
    game.pov.health = 0
    // changedhealth will be called again so the onhealthzero script will run
  }
}
game.povstatusattributes = NewStringDictionary()
dictionary add (game.povstatusattributes, "health", "Health: !")

And, again, you can play with the pane's displayed text like this:

dictionary remove(game.povstatusattributes, "health")
dictionary add (game.povstatusattributes, "health", "THIS IS YOUR HEALTH: !")

NOTES: These lines would go after the last line of the above script.

You would also need to add this if you want the player to actually die:

game.onhealthzero => {
  msg ("You have died.")
  finish
}

You could also turn that on in the editor:

image


@K.V. Ahhh.... *explitive.
So that's why The Pixie used "hit points"...


@ jmnevil54

So that's why The Pixie used "hit points"...

The Pixie is both wise and knowledgeable. (mumble, grumble, curse)

I'm just resourceful...


K.V. did something. Link. http://textadventures.co.uk/forum/quest/topic/yg5skhiixk2h6ja2e01vxq/time-keeping-methods


hmm... if the built-in in health isn't 'player.health'...

is the built-in 'health' than an Attribute of the 'game' Game Settings Object ???

does: 'game.health', work?


@HK

It's player.health by default when you turn on Health in the Features tab under the game object.

...but, if you DON'T enable that, to get it all working from a start script, you can do this:

http://textadventures.co.uk/forum/quest/topic/8rgyroemuk2llqfnydk-iq/increasing-the-value-of-an-attribute#4d92090b-5a6f-4a9b-944c-6cf0f6496a62


K.V I just realized that this ">" symbol was backwards, no wonder it wouldn't work. It's supposed to be AFTER Time.minutes has reached 1260 (9 PM). No it is not is a turn script, I use the SetTurnTimeout instead. No, Time.minutes never resets to 0. Time is measures only in minutes - I haven't done it yet but when Time.mintues = 12:00 AM, it will reset to 0.

Mrangel no the message does not appear at all, but it's likely do the the fact which I previously stated - I accidentally reversed my intention. There is no error code either.

K.V thanks for the file but I won't need it because it does not follow what the game is suppsoed to be like. For the record, I have no idea how to work dictionaries yet, so you'll have to inform me on it.

Jmnevil54 I did use the built in health in my script parenting the display of health.


No it is not is a turn script, I use the SetTurnTimeout instead.

There are numerous ways of calling SetTurnTimeout. (Creating a SetTurnTimeout isn't enough. You have to call the function.)

Some of the ways to call a function:

  • Start script

  • room enter script

  • room exit script

  • turn script

  • upon entering a command

  • upon opening something

  • upon closing something

  • upon switching something on

  • upon switching something off

  • ...

  • Basically, there are infinite possibilities.


How are you calling the SetTurnTimeout?

(I think you said it was in a turn script, but, if that's the case, the player should have started to die from the beginning when it was set up <=1260.)


No, Time.minutes never resets to 0.

Cool. That's one of my theories: debunked.


Mrangel no the message does not appear at all, but it's likely do the the fact which I previously stated - I accidentally reversed my intention.

It should have printed the message during every turn when you had <= 1260. (Wouldn't you agree?)

That's why I keep asking: how are you calling the SetTurnTimeout? (I don't think it is being called.)


K.V thanks for the file but I won't need it because it does not follow what the game is suppsoed to be like.

Did you play it and see if the player died the way you want the player to die?

I only provided the example for you to be able to experience the codes we're suggesting in action.

In the example:

  • play begins at 9 am
  • each turn is 12 minutes (so every five turns = 1 hour)
  • at 6 am, the player begins losing 5% health every turn

I'm not being unpleasant when I ask this, I promise:

What am I missing?


If you post your code (or each part of your code which has anything to do with time and health), we can see if (and how) you're calling your scripts, including SetTurnTimeout.


Ways to post code I use/someone else

  1. Copy-paste
  2. Word thing (git-hub, wordpad, I use Deviantart)
  3. Screenshot (google how to, then upload to imgur or something)
  4. E-mail (Hey, I've done it...)

K.V I can't show you my game's script because I can't download my game (which was made on the desktop) and use it in Quest. "Server Error in '/' Application" blah blah blah.


The servor was down. I need to check.

Edit:
I was able to edit and play my games. It works!

Try downloading your thing now.


Still doing it.


Try now.


Log in to post a reply.

Support

Forums