How do I make a value absolute?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Hedgo
Prole
Posts: 6
Joined: Fri May 13, 2022 7:54 pm
Location: The Bottom of the Barrel
Contact:

How do I make a value absolute?

Post by Hedgo »

I've skimmed through the wiki and forum, can't find the answer.
Sorry if this is dumb.
Drawing like it's the wild west.

Discord: currentlyjammin
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: How do I make a value absolute?

Post by BrotSagtMist »

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.
obey
MrFariator
Party member
Posts: 548
Joined: Wed Oct 05, 2016 11:53 am

Re: How do I make a value absolute?

Post by MrFariator »

If you mean to take the absolute value of a number, the function you're looking for is math.abs:

Code: Select all

local value = -2
value = math.abs(value)
print(value) -- prints 2
However, if you mean something like a constant value, ie. a value that can not be changed, that's a bit more complicated topic.
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: How do I make a value absolute?

Post by BrotSagtMist »

Oh i read this as obsolete. My bad.
obey
User avatar
Hedgo
Prole
Posts: 6
Joined: Fri May 13, 2022 7:54 pm
Location: The Bottom of the Barrel
Contact:

Re: How do I make a value absolute?

Post by Hedgo »

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.)
sonicproto.love
(3.64 KiB) Downloaded 34 times
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
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: How do I make a value absolute?

Post by BrotSagtMist »

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.
obey
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest