Missing something obvious...
|
|
Amael Juran
Zensual Sculpture
Join date: 3 Mar 2007
Posts: 41
|
04-16-2008 11:20
Ok, so I'm new to LSL and thought I'd try something simple stupid... which has now backfired spectacularly. Could someone please tell me what the blazes is wrong with the following?:
default { touch_start(integer total_number) { float g = 0; g = 220/256; llSay( DEBUG_CHANNEL, "g has a value of: " + (string)g ); } }
It keeps on saying that g is 0.000 when it should be 0.86???
Thanks in advance!
|
|
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
|
04-16-2008 11:22
You stated g = 0, and then in the same event stated g = 220/250. When declaring a variable, you can just put something like From: someone float g; g = 220/250;
Without any initial value for 'g'. Otherwise you're contradicting yourself, and saying it has two values.
_____________________
Tutorials for Sculpties using Blender! Http://www.youtube.com/user/BlenderSL
|
|
Amael Juran
Zensual Sculpture
Join date: 3 Mar 2007
Posts: 41
|
04-16-2008 11:27
From: Keira Wells You stated g = 0, and then in the same event stated g = 220/250.
When declaring a variable, you can just put something like
Without any initial value for 'g'. Otherwise you're contradicting yourself, and saying it has two values. Thanks for the reply but I'm now even more confused- if that's the case, then how am I supposed to actually do any operations on the variable? E.g. Say g starts off as 1.2 and I want to change it later in the same touch state to another value. PS: I just tried doing it your way and I'm still getting the same thing
|
|
Borat Kungler
Registered User
Join date: 13 Apr 2007
Posts: 33
|
04-16-2008 11:33
From: Keira Wells You stated g = 0, and then in the same event stated g = 220/250. When declaring a variable, you can just put something like Without any initial value for 'g'. Otherwise you're contradicting yourself, and saying it has two values. Not declaring g as 0 won't make any difference to the output, as g's value will be re-assigned in the next line. However this code works.... default { touch_start(integer total_number) { float g; g = 220.0 / 256.0; llSay(0, "g has a value of: " + (string)g); } }
Added the .0 to the end of the numbers
|
|
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
|
04-16-2008 11:36
From: Borat Kungler Not declaring g as 0 won't make any difference to the output, as g's value will be re-assigned in the next line. I thought that was the case, but it was all I could think of. Upon thinking on it, was the problem caused by it being a float, and the equation using integers? Without the .0, they might be seen only as integers to the system, I mean, I'm not sure. (Ive never thought about it before)
_____________________
Tutorials for Sculpties using Blender! Http://www.youtube.com/user/BlenderSL
|
|
Amael Juran
Zensual Sculpture
Join date: 3 Mar 2007
Posts: 41
|
04-16-2008 11:38
From: Borat Kungler Not declaring g as 0 won't make any difference to the output, as g's value will be re-assigned in the next line. However this code works.... default { touch_start(integer total_number) { float g; g = 220.0 / 256.0; llSay(0, "g has a value of: " + (string)g); } }
Added the .0 to the end of the numbers Oh for crying out loud... knew it had to be something obvious! Thanks a million for the help Borat & Keira- much appreciated!
|
|
Borat Kungler
Registered User
Join date: 13 Apr 2007
Posts: 33
|
04-16-2008 11:39
From: Keira Wells Upon thinking on it, was the problem caused by it being a float, and the equation using integers? Without the .0, they might be seen only as integers to the system, I mean, I'm not sure. I believe so yes, once I had added the .0 on the end they were recognized as being floats, another way of doing it (although obviously klunky) is to cast the integers to floats like (float)220 / (float)250 YW Amael 
|
|
Nika Talaj
now you see her ...
Join date: 2 Jan 2007
Posts: 5,449
|
04-16-2008 11:39
When you do the integer divide 220/256, you are i believe implicitly coercing g to be an integer, even if you had declared it as:
float g=0.0;
which would be a safer declaration. LSL is picky that way. .
|