I've skimmed through the wiki and forum, can't find the answer.
Sorry if this is dumb.
How do I make a value absolute?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How do I make a value absolute?
Drawing like it's the wild west.
Discord: currentlyjammin
Discord: currentlyjammin
- BrotSagtMist
- Party member
- Posts: 657
- Joined: Fri Aug 06, 2021 10:30 pm
Re: How do I make a value absolute?
Yes, yes it is.
I am not entirely sure what you want but ill just assume you mean deleting something?
That would be value=nil.
I am not entirely sure what you want but ill just assume you mean deleting something?
That would be value=nil.
obey
-
- Party member
- Posts: 548
- Joined: Wed Oct 05, 2016 11:53 am
Re: How do I make a value absolute?
If you mean to take the absolute value of a number, the function you're looking for is math.abs:
However, if you mean something like a constant value, ie. a value that can not be changed, that's a bit more complicated topic.
Code: Select all
local value = -2
value = math.abs(value)
print(value) -- prints 2
- BrotSagtMist
- Party member
- Posts: 657
- Joined: Fri Aug 06, 2021 10:30 pm
Re: How do I make a value absolute?
Since I've already made this thread I might as well ask about another problem I'm having.
I'm trying to make a Sonic game and for some reason, I can't get the momentum quite working. I've used virtually the same code on Scratch and it works there, so maybe I messed something up in the process of turning it into LUA, but I can only get the player to move correctly if they're moving right. If I press left they just won't move. (properly, at least.)
There's the love file. The code is a mess from trying to experiment but it's clearly has been in vain. Thanks to whoever helps.
I'm trying to make a Sonic game and for some reason, I can't get the momentum quite working. I've used virtually the same code on Scratch and it works there, so maybe I messed something up in the process of turning it into LUA, but I can only get the player to move correctly if they're moving right. If I press left they just won't move. (properly, at least.)
There's the love file. The code is a mess from trying to experiment but it's clearly has been in vain. Thanks to whoever helps.
Drawing like it's the wild west.
Discord: currentlyjammin
Discord: currentlyjammin
- BrotSagtMist
- Party member
- Posts: 657
- Joined: Fri Aug 06, 2021 10:30 pm
Re: How do I make a value absolute?
I was about too say this looks easy but the longer i look at it the less i understand.
Honestly, start from scratch.
You simply dont have to deal with signs at all.
The position is composed of currentpos+ accellerate*dt.
And accelerate=(accelerate -leftbutton +rightbutton) * resistance (That is, a float smaller 1).
Makes, including keys, 4 lines for a basic left/right movement.
This whole if cases for negative positive directions wont get you anywhere.
Honestly, start from scratch.
You simply dont have to deal with signs at all.
The position is composed of currentpos+ accellerate*dt.
And accelerate=(accelerate -leftbutton +rightbutton) * resistance (That is, a float smaller 1).
Makes, including keys, 4 lines for a basic left/right movement.
This whole if cases for negative positive directions wont get you anywhere.
obey
Who is online
Users browsing this forum: Google [Bot] and 5 guests