Page 1 of 1
Negative integers?
Posted: Sun Nov 11, 2012 6:15 am
by tomshreds
Hi,
I was wondering, I need my in-game balance to go negative at some times in my game.
How could I do this? I'd like to be able to have a balance of -1450 for example. And then earn some money and go positive, etc.
Any idea?
Thanks!
Re: Negative integers?
Posted: Sun Nov 11, 2012 7:13 am
by OmarShehata
So...where's the problem?
Code: Select all
local balance = 10;
balance = balance - 100;
print(balance);
balance = balance + 200;
print(balance);
Re: Negative integers?
Posted: Sun Nov 11, 2012 7:17 am
by tomshreds
OmarShehata wrote:So...where's the problem?
Code: Select all
local balance = 10;
balance = balance - 100;
print(balance);
balance = balance + 200;
print(balance);
Frankly, I was sure lua wasn't going to do this. So sure that I didn't tested it.
Thanks for this and sorry :-S
Re: Negative integers?
Posted: Sun Nov 11, 2012 8:31 am
by Robin
tomshreds wrote:Frankly, I was sure lua wasn't going to do this.
I'm really interested in what led you to that belief. Do you know why, or just have a good guess about it?
Re: Negative integers?
Posted: Sun Nov 11, 2012 9:21 am
by T-Bone
I think that every single programming language ever has supported negative numbers.
Re: Negative integers?
Posted: Sun Nov 11, 2012 2:31 pm
by YellowAfterlife
T-Bone wrote:I think that every single programming language ever has supported negative numbers.
Some languages also support unsigned number types;
Some of
RISC architectures may leave signed number implementation to programmer for various reasons.