Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

I am trying to make a loop to detect if something has changed.  Normally I'd use a previous and current variable, like so:


:set_integer var="prev_val" value="current_val"; //  <- store previous value

:gosub("randomly_change_current_val");

:if (prev_val != current_val){    // <- test for change

 : print "something changed.";

}


, but I can't seem to get the value to be evaluated as an integer, it just thinks I keep meaning the word.  I've tried lots of permutations but I can't seem to assign the value of a variable into another variable.   Is this possible?   I'm implementing a workaround for now using a loop, but I suspect I'll blow the stack if I'm not careful.  It's a nasty hack :)


make_equal : subroutine {

  :  if (prev_val < current_val) { :increment "prev_val";  :gosub "make_equal"; }

   :else_if (prev_val > current_val) {:decrement "prev_val"; :gosub "make_equal";}

}

(+1)

It's in the documentation. The value="" always expects an integer value, and will interpret it as an integer.

:set_integer var="prev_val" value="current_val"; 

To set based on the result of an expression (which can reference an integer variable) use:

:set_integer var="prev_val" {(current_val)}
(1 edit)

Ahh!  OK.  The first one was what I was trying, and it just kept saying invalid integer "current_val", as you'd expect.

I think my attempts to do the second one failed because of a bug elsewhere in the subroutines block, but the error always seemed to gravitate to the "}" at the end of the block...  Thanks again!  I've removed my shonky iterative setter. :)

Perhaps a concrete example of setting a variable equal to another variable in the documentation might help new users?

(+1)

I might just add a : copyvar; command even though it's technically redundant. Might be good for users that don't want to go into the EXPRESSION FORM rabbit hole.