Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ Variable value assignment speed

Variable value assignment speed

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Kevnuke   USA  (145 posts)  Bio
Date Thu 16 Aug 2018 05:55 AM (UTC)
Message
I'm not really sure how to ask this. I'm updating my curing system for Achaea. and since it needs so much work anyway, I figured I may as well update other things too.

Is a boolean value faster to assign or compare to something else than integers? I might change my arrays to hold values of 1 or 0 instead of true/false if it's more efficient. Also, some afflictions can be have up to 8 (I think) levels, so those might have to be integer assignments anyway. For example, aff.wristfractures = 4 (up to 8), if I get hit with an attack enough times for my wrists to be fractured 4 times.

Does the logic in Lua see integer 1 and boolean true as equal? Like:


if 1 == true then
  Note ("True")
end
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 16 Aug 2018 06:11 AM (UTC)

Amended on Thu 16 Aug 2018 06:13 AM (UTC) by Nick Gammon

Message
Lua is quite fast so I wouldn't fiddle with minor stuff like that. The mapper I wrote draws dozens of rooms (each requiring lots of calculations) in a fraction of a second.

I doubt there is much difference in assigning a number of a boolean (or indeed, a string) because internally they are held as 4 byte fields.

Quote:

Does the logic in Lua see integer 1 and boolean true as equal? Like:


if 1 == true then
  Note ("True")
end




Lua sees nil and false as false and everything else as true. So, for example, an empty string, or the number 0 are true.

Anyway, you can test that sort of thing for yourself.

The number 1 (a floating point number) and the value true (a boolean) will not compare equal.

To write an "if" test for true just write:


if true then
  Note ("True")
end


Or, for example:


if a > 5 then
  Note ("a is greater than 5")
end


Comparisons will return a boolean (so "a == 5") would resolve to either true or false.

However just because you can write:


if 42 then
  print "True"
end

if 666 then
  print "True"
end


That does not mean that 42 is equal to 666, although they are both considered to be true values in an "if" test (because neither of them are nil or false).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Thu 16 Aug 2018 06:14 AM (UTC)
Message
Even this will print false:


print (nil == false)


They are both considered false but they are different to each other.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Kevnuke   USA  (145 posts)  Bio
Date Reply #3 on Thu 16 Aug 2018 09:21 AM (UTC)
Message
I suppose nil is a lack of any value and boolean false is a deliberate value of false.

Thank you for the clarification
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #4 on Sun 19 Aug 2018 01:37 AM (UTC)
Message
Quote:
Is a boolean value faster to assign or compare to something else than integers?

I doubt that you're doing enough comparisons and assignments for it to matter. In my experience, the main things to optimize are screen drawing and sqlite access. Everything else may as well be instantaneous.

https://github.com/fiendish/aardwolfclientpackage
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


14,156 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.