Typecast a key into an integer?
|
|
Weasel Wingtips
Registered User
Join date: 17 Sep 2007
Posts: 7
|
02-10-2008 09:02
I'm scratching my head on how to get this done:
integer interval; link_message(integer sender_num, integer num, string msg, key msg2) { interval = msg2 }
Returns a type mismatch error.
If I try "interval = (integer)msg2" or if I even cast the type as integer instead of key in the link_message I also get type mismatch errors.
Any idea why, or how I can work around it?
|
|
Boreal Latte
Registered User
Join date: 15 Nov 2007
Posts: 104
|
02-10-2008 09:19
One cannot cast a key into an integer. The key does not contain a number, but a guid, which contain more information than what can be stored in an integer.
It is not quite clear what you are trying to do with your code. Why not declare interval as key?
|
|
Weasel Wingtips
Registered User
Join date: 17 Sep 2007
Posts: 7
|
02-10-2008 09:28
The Wiki says that link_message's KEY input can be reused as string data, which I do in multiple other places in the script. All I have to do is say
string varaible = (string)msg2
Now I've come across a circumstance where I want to make a calculation with the msg2 field; eg:
integer total = 15 + msg2;
msg2's value in this called instance is a single-digit integer.
You can't perform 'maths' if I typecast it to key, can I?
|
|
Ravanne Sullivan
Pole Dancer Extraordinair
Join date: 10 Dec 2005
Posts: 674
|
02-10-2008 09:44
From: Weasel Wingtips The Wiki says that link_message's KEY input can be reused as string data, which I do in multiple other places in the script. All I have to do is say
string varaible = (string)msg2
Now I've come across a circumstance where I want to make a calculation with the msg2 field; eg:
integer total = 15 + msg2;
msg2's value in this called instance is a single-digit integer.
You can't perform 'maths' if I typecast it to key, can I? How about either integer total = 15 + (integer)msg2; or integer total = 15 + (integer)variable;
|
|
Weasel Wingtips
Registered User
Join date: 17 Sep 2007
Posts: 7
|
02-10-2008 10:10
integer total = 15 + (integer)msg2 returns a type mismatch error as well as it is trying to convert key-msg2 to integer-msg2 I'm thinking. :/ integer total = 15 + (integer) variable DOES work, however the integer variable is not located in the script and is being passed in by msg2 
|
|
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
|
02-10-2008 10:54
default { state_entry() { key test = "1234"; integer result = 15 + (integer)((string)test); } } This should do what you need... You first typecast the Key to a String, then to an Integer. At least, that passes the lslint test, but I'm not in-world to fully test that.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
02-10-2008 12:06
you might be able to get away with
interval = (string)msg2;
but youre safer converting it to integer as well, as Robby demonstrated
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Weasel Wingtips
Registered User
Join date: 17 Sep 2007
Posts: 7
|
02-15-2008 18:55
From: RobbyRacoon Olmstead integer result = 15 + (integer)((string)test);
That did the trick, thanks so much. I feel ashamed that it was so simple. :/
|
|
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
|
02-15-2008 18:58
From: Weasel Wingtips That did the trick, thanks so much. I feel ashamed that it was so simple. :/ Heh, if only you knew how often that happens you'd feel better  Sometimes you just gotta take a break and change mental gears for a bit. Glad it helped!
|