Increasing Attribute value is not working for me

Clarky
29 Dec 2020, 16:47

So I was reading this > http://docs.textadventures.co.uk/quest/keeping_score.html

msg("You jump into the air. Hurrah!")
game.score = game.score + 1

And thought it looked easy enough for what I'm doing, which is taking HHMMSS and turning it into 24hr time.

  msg ("<br/>>>> Report at Fix <<<<br/>")
  get input {
    OBFIX1.value = result
    OBFIX1.value = OBFIX1.value+120000
    msg ("{OBFIX1.value} Hrs Recorded Successfully.")
  }

But I only get this: 100000120000 Hrs Recorded Successfully.
My input is 100000, so i should be getting 220000.

BTW are there any good tutorials I can read online that would make doing basic things like this easier for me? As you can imagine, not alot of the Quest documentation is making much sense to a non-coder, especially when it doesnt work out.

Once I get this bit to work, I want to take two attributes (both 24 hr time hhmmss) and subtract them, to find the time difference.
And then I want to do a heap of other calculations to determine how long it would take for the object to hit the ground.

Happy to teach myself, but i don't know much.


Richard Headkid
29 Dec 2020, 19:18

Hello.

Is OBFIX1.value a string or a number?

If it is a string, say "100000", then OBFIX1.value + 120000 would result in a string: "100000120000".

It would be like if OBFIX1.value was the string "Richard". Then, OBFIX1.value + 120000 would result in a string: "Richard120000".


This might not be your issue. Just a wild guess.


BTW are there any good tutorials I can read online that would make doing basic things like this easier for me?

http://docs.textadventures.co.uk/quest/tutorial/index.html


Richard Headkid
29 Dec 2020, 19:26

PS

Quest - A Quick Introduction https://www.youtube.com/watch?v=7vIi0U4rSX4


Quest 1 - Creating a game https://www.youtube.com/watch?v=ILUMd7Um1IM


Lets Make An RPG in Quest https://www.youtube.com/watch?v=gKwVvT5Tyy0

(This video is part of a playlist: https://www.youtube.com/playlist?list=PLVDq5KtDCqnZzUqLZ8v-3L7icnvyV6n_d)


Richard Headkid
29 Dec 2020, 19:40

I made a "test" command to illustrate.

player.val = 100000
player.value = "100000"
player.val = player.val + 120000
player.value = player.value + 120000
msg ("player.val:")
msg (player.val)
msg ("player.value:")
msg (player.value)

> test
player.val:
220000
player.value:
100000120000


Clarky
30 Dec 2020, 04:43

So yeah your example works fine for me to, I've experiemented with setting the attribute an initial value such as 10, then added 10 and I get 20 as expected.
But it doesn't work when one of the numbers comes from the command box (get input), so it must have something to with this line > OBFIX1.value = result

Like your example showed me, it must be a string or something other than an integer.

Would be good if this tutorial would just elaborate on doing more things with the eggs example > http://docs.textadventures.co.uk/quest/tutorial/custom_attributes.html.

How many grams of eggs would you like to throw at the car?
Input > 100
You threw 100 grams of eggs, there is 400 grams of eggs remaining.
Input > 20
You threw 20g of eggs, there is 380 grams of eggs remaining.


mrangel
30 Dec 2020, 09:02

The result from get input is always a string. If you want an int, you would need to make it:
OBFIX1.value = ToInt (result)


Clarky
30 Dec 2020, 09:10

Awesome, should be right now.

Thanks.


Pertex
30 Dec 2020, 15:25

But don't forget to check the input for a number.If the player enters "one thousand", there will be an error.

if (IsInt(result)){
  OBFIX1.value = ToInt (result)
}

Clarky
01 Jan 2021, 20:49

Thanks.

Just 1 more question but - I'm trying to use a variable as a interval for a TIMER, but it doesn't seem to work for me.
I tried creating a timer "freefall1" , then using "Set Timer" and "Enable Timer", as below:

SetTimerInterval (freefall1, obfreefall1.value)
EnableTimer (freefall1)

I've tried a timeout:
SetTimeout (obfreefall1.value) {
msg ("My Timer")
}

I'm sure it's something basic...


mrangel
02 Jan 2021, 01:34

Are you sure you're waiting long enough for the timeout to trigger? It could take a few seconds longer than you expect.

I assume that you've checked the variable is an int.


Clarky
02 Jan 2021, 09:11

The variable prints to screen as it should, such as - Time to Ground: 24
And I've been using IsInt and InInt as per above.

Timers and Timeout works fine when I enter a number as seconds, but not when I set it to expression and enter the variable.


Clarky
02 Jan 2021, 13:05
get input {
    if ((IsInt(result))) {
      obheight1.value = ToInt (result)
    }
    obfreefall1.value = obheight1.value  *  0.0048
    msg (" Recorded {obfreefall1.value} Seconds")
  }

mrangel
02 Jan 2021, 19:03

I can't see any problems with that.

I know timers don't work properly with precise times; but I'm not sure if using a floating point number for the interval will round it off, or just be ignored.

Does it work if you change

obfreefall1.value = obheight1.value  *  0.0048

to

obfreefall1.value = obheight1.value  *  3/625

?
That's the same number, but will round off the answer to be an int.


Clarky
03 Jan 2021, 04:28

yep thats working now. Cheers.