Home / Forum / Discussion and Help for Gmod-Glua-Lua / Change the negative number into a positive number ✔️ Solved
Thread | |
---|---|
⚗️ Support 📖 Posts: 31 ↩️ Replies: 42 ❤️ Reactions: 18 |
Jenny Fer
Posted 1575183233 (Edited) (13876 views)Hello I want to get a positive number with a negative number on Gmod. An idea how to do without using the math.abs() functions? For example, a -255 when printed does not display the -255 but 255. ⛔️ Sorry, you are not connected, join to leave a reaction
|
Replies | |
---|---|
🎁 Buyer 📖 Posts: 4 ↩️ Replies: 18 ❤️ Reactions: 1 |
Orion Posted 1575184330hmm ill try out some stuff, ill reply or message you on discord if i figure it out 🙃 |
🎁 Buyer 📖 Posts: 4 ↩️ Replies: 18 ❤️ Reactions: 1 |
Orion Posted 1575184546testvar = -255 if testvar < 0 then testvar = testvar - testvar - testvar end print( testvar ) This is very primitive, it works tho! |
🎨 Creator 📖 Posts: 164 ↩️ Replies: 76 ❤️ Reactions: 25 |
Norda Scripts Posted 1575185345Hi there are plenty of solutions. The most optimized are this one Multiply it by -1:
If you use a negative number to subtract it from 0 it also turns it into a positive number :
I have just tested each method, some are less efficient than others and it is up to you to choose. On Gmod math.abs() is faster. |
🎁 Buyer 📖 Posts: 4 ↩️ Replies: 18 ❤️ Reactions: 1 |
Orion Posted 1575185642perfection david |
🎨 Creator 📖 Posts: 164 ↩️ Replies: 76 ❤️ Reactions: 25 |
Norda Scripts Posted 1575185662Tested with n - n - n it work but too heavy for GMod. |
🎨 Creator 📖 Posts: 164 ↩️ Replies: 76 ❤️ Reactions: 25 |
Norda Scripts Posted 1575185739Thank you Orion. 🙂 |
🎁 Buyer 📖 Posts: 4 ↩️ Replies: 18 ❤️ Reactions: 1 |
Orion Posted 1575186100🙃 |
🎨 Creator 📖 Posts: 164 ↩️ Replies: 76 ❤️ Reactions: 25 |
Norda Scripts Posted 1575186128It is a good idea Orion
|
🎨 Creator 📖 Posts: 164 ↩️ Replies: 76 ❤️ Reactions: 25 |
Norda Scripts Posted 1575186741Question why? |
⚗️ Support 📖 Posts: 31 ↩️ Replies: 42 ❤️ Reactions: 18 |
Jenny Fer Posted 1575187332Oh I'm...!! Thank!!! Because I updated my scripts to create an alternative for math.mod will be deleted from gmod and also math.Dist I wouldn't want my scripts to be broken by an update of GMod. I reduce this risk by doing this. If I replace math.abs by a simple mathematical solution and not too heavy. I'm going to use (n * -1) it's quick for my needs. |
🎁 Buyer 📖 Posts: 4 ↩️ Replies: 18 ❤️ Reactions: 1 |
Orion Posted 1575187455oh ok! 🙃 |
🎨 Creator 📖 Posts: 164 ↩️ Replies: 76 ❤️ Reactions: 25 |
Norda Scripts Posted 1575188049I understand. I was thinking about something else. Then. I tested again the solution n * -1, Is the best alternative among those proposed : 0.004s is good. 🙂 |
⚗️ Support 📖 Posts: 31 ↩️ Replies: 42 ❤️ Reactions: 18 |
Jenny Fer Posted 1575220399Thank you. I learned that a subtraction is heavier than a multiplication. This is important for future choices. 🙄 |