How to flip a negative number to positive?

Okay, short backstory: This variable determines if slaver guards are before the front gate. If it's 0, no guards. If it's -1, yeah, there are guards but you don't know about them. If it's 1, there are guards and you DO know about them.

If you use a binoculars, you can see from a distance and spot the guards. Okay, so why dosn't this work in the binoculars code? It still returns a -1. The thing is, there are a lot of conditions I need to reveal if you scope the target.

{if slvFrontGateGuard<0:{@slvFrontGateGuard*=-1}}

Ideas?


Does regular Javascript work? I'm new to Squiffy coding but If that code is running after used the binoculars then you can just <your variable> = Math.abs(<your variable>) and that will always return a 1 no if statement required.


If the only options are -1, 0, and 1, could you just do:

{if slvFrontGateGuard=-1:{@slvFrontGateGuard=1}}

(Or whatever the code looks like; this isn't a language I'm familiar with)

I might also have suggested the javascript option; don't know if there's a better way to do this in Squiffy, but the code you posted looks valid.


Well, I eventually had to make each of the approaches an individual section anyway so I was able to tailor make the javascript to work with only that value (i.e. -1, -2, -3). But the value of the negative determined the direction you approached from.

    if (get("slvOutsideGuard")==-2){set("yourJump",false);set("slvFrontGateGuard",2);}

This is still frustrating. From what I understand, the original code should have worked. ABS() didn't work either - tried that too.


Log in to post a reply.

Support

Forums