Help with Calculation

Have any questions or problems in making your game, subscribing and/or using our software? Post here.
Forum rules
Make sure you are using the newest version. This can be downloaded at the top of the site via the "downloads" link.

Use a very good subject. "Problem" or "Help" are unacceptable titles.

Use the search feature before posting a question, as the answer is probably already here.

Subscript out of range error 9: This is a generic error, and we'll need way more information than that to figure out the problem. If you get this, strongly consider following the instructions of submitting your project through the Submit Bug feature within the editor.
User avatar
thebluejester
001 Enthusiast
 
Joined: Fri Jul 24, 2015 3:05 am

Help with Calculation

Postby thebluejester » Wed Oct 26, 2016 6:39 am

Hi all!

I'm a bit confused / stuck trying to do a fairly simple calculation.
I want to divide numbers by 3 and only get the whole integer back, no decimals.

I had the following Math:
Attack = Actor's Stat (5)
Remainder = Modulus (Attack & 3) (Should return the remainder of 5 / 3 so 2)
Attack = Attack - Value1 ( 5 - 2 = 3)
Attack = Attack / 3 ( 3 / 3 = 1)

I have it working sometimes and not others.
I did Modulus 15 / 3 and got 14...
and in another 2 case it always returns 0 regardless of the the numbers given...

Could someone embed a script that uses Modulus correctly?

(I would embed my script but I couldn't work out how to do it, I've seen it done though...)

User avatar
AnvilHouse
001 Support
 
Joined: Mon Mar 04, 2013 1:19 am
Location: Wisconsin, USA

Re: Help with Calculation

Postby AnvilHouse » Wed Oct 26, 2016 12:18 pm

here is a shot that would cover the sharing of script and rounding :P

pretty simple here

Image

now when it comes to modulus i still dont get it XD numbers would be much better at it
Image Image Image

https://www.patreon.com/Anvilhouse ...yes...I am on Patreon!


-The store is under construction-
All items are guaranteed to work with 001 ;)

User avatar
Shingu
001 Supporter
 
Joined: Sun Nov 22, 2015 2:50 pm

Re: Help with Calculation

Postby Shingu » Wed Oct 26, 2016 1:47 pm

thebluejester wrote:I want to divide numbers by 3 and only get the whole integer back, no decimals.

In my scripts I use it (attachment) and it seems to work:
Attachments
Sem título.png
Sem título.png (9.91 KiB) Viewed 732 times
Image
Image

User avatar
thebluejester
001 Enthusiast
 
Joined: Fri Jul 24, 2015 3:05 am

Re: Help with Calculation

Postby thebluejester » Wed Oct 26, 2016 8:59 pm

I feel so dumb, how did I completely overlook the entire maths functions section! I knew it was there. Argh!

Thank you both! This support forum is filled with the best people :)

User avatar
Mr.Numbers
001 Support
 
Joined: Wed Feb 28, 2007 1:50 am
Location: Alberta, Canada

Re: Help with Calculation

Postby Mr.Numbers » Thu Oct 27, 2016 4:05 am

Protip, using a backslash instead of a forward slash in math calculations will automatically return an integer (No decimals)

For instance:

10 \ 3
Would return
3

10 / 3
Would return
3.33333333...
Image
I AM THE ALL MIGHTY SCRIPTING MASTER
Please do not PM me with Engine 001 related questions, rather post on the forums. ;)

User avatar
thebluejester
001 Enthusiast
 
Joined: Fri Jul 24, 2015 3:05 am

Re: Help with Calculation

Postby thebluejester » Thu Oct 27, 2016 6:01 am

That's awesome!
Thanks Mr. Numbers!


Return to Technical Support Questions

Who is online

Users browsing this forum: No registered users

cron