#Help with a Timer

1 messages · Page 1 of 1 (latest)

rich ginkgo
#

Ok so I'm assuming I'm getting the errors because of the different variable types.
I am using the variable "X" as a value for infinite/manual removal.

[h: listCount(ConditionList)]

[foreach(Condition, ConditionList, ", "), code: {
    [h: ConditionInfo=json.get(Conditions, Condition)]
    [h: json.toVars(ConditionInfo)]
    [h: OldTimer=Timer)]
    [if(OldTimer=="X"), code: {[NewTimer="X"]};{[NewTimer=OldTimer-1]}]
    [if(NewTimer=="X" || NewTimer>=0), CODE: {Yes};{No}]
}]```
This obviously isn't the finished code, and I'm just running it through to get it to work.
chilly nexus
#

What error are you getting? But at the very least: [h: OldTimer=Timer)] has an extraneous parenthesis

#

Also, side note, if you have Conditions as an array already, you don't need to convert it to a string list to use foreach() on it - you can just use the array itself the same way

rich ginkgo
chilly nexus
#

Ah, I see, thought it was an array, not an object

rich ginkgo
#

I'm not the best at coding lol...I still don't even know the difference between Objects and Arrays

chilly nexus
#

Are you literally setting the value of NewTimer to "X", or is "X" a variable? because it will yell at you if you try to ask if a string is greater than a number

rich ginkgo
#

Well I don't like being yelled at so.....

#

I mean yes I used X because what is a number for Infinite

#

I've even tried just leaving the code empty using "" as the value. Sorry not variable, but Value

chilly nexus
#

Also for arrays vs. objects - an array is an ordered set, like [1,2,3,4,5]. In an array you use its position to reference something in the array, starting from index 0.

An object is an unordered set, where you use a key to reference something in the array. So if you wanted to describe the properties of a shirt, you might do something like {"SleeveLength":"Short","Material":"Cotton","Size":"Medium"}, etc.

#

So if you want to know the size of the shirt, you just do json.get("Size").

#

Back to the timer - not sure how "X" is being set, but you have two obvious options that jump out at me.

Option #1: Split the if(): into two separate ones, checking if NewTimer=="X" first, then checking NewTimer>=0. The first will filter out any timers that are set to a string, avoiding comparing string to number (== string to number is fine).

Option #2: Instead of using "X" for infinity, use some large number that you wouldn't expect the timer to reach anyway. Not sure if this is feasible for how your timer is set up, but it's an option.

rich ginkgo
#

ok I'll try option 1 and see.
Option 2 I've thought about doing that, but then I have a display function in the properties that shows the countdown.
Thank you for you help.

chilly nexus
#

No problem!