Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

math doesn't work in a datamap

JexJex
edited September 2016 in Help! with 2.0
I kept getting errors trying to do a simple <= and $var - $var.
the error message was it was expecting a string and wouldn't add them.

when i took the $var out of a datamap and made them unique independent variables the error went away.

wondering if anyone else encountered this issue?


code:
(set: $tick's battrack to $tick's roomtrack) and
(if: (30 <= ($tick's roomtrack - $tick's battrack)) is true)[true]
produces an error about booleans and strings

code:
(set: $roomtrack to 30)(set: $battrack to 0)
(if: (30 <= ($roomtrack - $battrack)) is true)[true]
produces [True]

Comments

  • How are you defining the (datamap:) entries?

    Also, comparing a conditional expression to one of the boolean values is totally unnecessary and you don't need the extra parenthesis. For example:
    <!-- Unnecessary boolean value comparison and parens. -->
    (if: (30 <= ($tick's roomtrack - $tick's battrack)) is true)[true]
    
    <!-- Better. -->
    (if: 30 <= ($tick's roomtrack - $tick's battrack))[true]
    
    <!-- Best. -->
    (if: 30 <= $tick's roomtrack - $tick's battrack)[true]
    
  • i actually added the is true within the parantheses later to see if that fixed it. it didn't.
    the datamap was set on the starting page:

    (set: $tick to (datamap: "roomtrack", 0, "battrack", 0))

    its now:
    (set: $roomtrack to 0)
    (set: $battrack to 0)

    its not a huge deal since i'm only tracking those 2 variables, a way to "pass time" by moving between passages, compared to when i "plugged a battery in to charge"
  • i doublechecked that all were numbers and not "0" strings. i then tried using (num: ) but that just screwed it up since they were already numbers....

    i honestly believe its a glitch in the datamap system.
  • @Jex: I think you need to check your maths.

    If you initialise your variable(s) like so (set: $tick to (datamap: "roomtrack", 0, "battrack", 0)) and then you subtract one from the other like so $tick's roomtrack - $tick's battrack then the result is going to equal zero.

    Because thirty is not less than or equal to zero the condition of your (if:) macro is going to return false, so the associated hook will not be processed.
    (set: $tick to (datamap: "roomtrack", 0, "battrack", 0)) \
    debug: roomtrack: (print: $tick's roomtrack), battrack: (print: $tick's battrack)
    
    ''Assign roomtrack's value to battrack'' \
    (set: $tick's battrack to $tick's roomtrack)
    debug: roomtrack: (print: $tick's roomtrack), battrack: (print: $tick's battrack)
    
    ''Minus battrack from roomtrack'' \
    (set: $result to $tick's roomtrack - $tick's battrack)
    debug: result: $result
    
    ''is 30 less than or equal to $result'' \
    (if: 30 <= $result)[Yes](else:)[No]
    

    Where as if you change roomtrack to a number larger than thirty (like forty) and remove the coed that assigns roomtrack value to battrack then your (if) condition will return true, which will cause the associated hook to be processed.
    (set: $tick to (datamap: "roomtrack", 40, "battrack", 0)) \
    debug: roomtrack: (print: $tick's roomtrack), battrack: (print: $tick's battrack)
    
    ''Minus battrack from roomtrack'' \
    (set: $result to $tick's roomtrack - $tick's battrack)
    debug: result: $result
    
    ''is 30 less than or equal to $result'' \
    (if: 30 <= $result)[Yes](else:)[No]
    
Sign In or Register to comment.