Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / [SOLVED] How to see if a 'variable' is positive or negative?

Author
Message
Mark Garrett
Reviewed AGK on Steam
18
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 18th Nov 2018 08:01 Edited at: 18th Nov 2018 08:19
How do you see if a 'float variable' is positive or negative?



I know 'c' is a negative variable in this example, and I can print (c) to find out; and I can look at it and know instantly that 'c' is negative.

But when my program is running, it needs to know when a variable is positive or negative. And I need to add it to my code,
because sometimes 'c' will be negative, and other times 'c' will be positive.

I could code 'if c<0' but then my code would be more complicated. So is there a more efficient way to code it?

The author of this post has marked a post as an answer.

Go to answer

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 18th Nov 2018 09:33
This post has been marked by the post author as the answer.
you could just code a simple function to test for a negative value



Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 18th Nov 2018 16:50
That's really no different than just doing

If c < 0
// is negative
else
// is positive
endif

Plus you add the overhead of a function call
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.

Login to post a reply

Server time is: 2024-04-25 00:25:42
Your offset time is: 2024-04-25 00:25:42