SalvadorNL Posted December 4, 2021 Share Posted December 4, 2021 its been a while since i last scripted, and this simple little thing is driving me crazy Quote if ((integer)msg) { integer min = -2147483648; integer max = 2147483647; integer input = (integer)msg; if (((integer)msg > min & (integer)msg < max) & (string)input == (string)msg) { llOwnerSay("New Channel: "+(string)msg); } If the user enters a number outside the scope, the input will result in; -1 , although this works, i wonder if there isn't a better/cleaner option ? Link to comment Share on other sites More sharing options...
KT Kingsley Posted December 4, 2021 Share Posted December 4, 2021 if ((string) ((integer) msg) == msg) might work here. 1 Link to comment Share on other sites More sharing options...
Profaitchikenz Haiku Posted December 4, 2021 Share Posted December 4, 2021 It depends on what you want to accomplish. If your goal is to get a channel for a listen hat is reasonably safe against duplication, there are better methods such as taking a portion of the user's UUID and converting that to a negative integer.. One safeguard you could try is to take the length of msg before trying to cast it to an integer and making sure it does not exceed the length of a string holding a maximum integer representation, and don't cast if the string is too long. 1 Link to comment Share on other sites More sharing options...
Mollymews Posted December 5, 2021 Share Posted December 5, 2021 another way is to use the hash of what the user enters http://wiki.secondlife.com/wiki/LlHash Link to comment Share on other sites More sharing options...
bobsknief Orsini Posted December 5, 2021 Share Posted December 5, 2021 13 hours ago, Profaitchikenz Haiku said: It depends on what you want to accomplish. If your goal is to get a channel for a listen hat is reasonably safe against duplication, there are better methods such as taking a portion of the user's UUID and converting that to a negative integer.. One safeguard you could try is to take the length of msg before trying to cast it to an integer and making sure it does not exceed the length of a string holding a maximum integer representation, and don't cast if the string is too long. For example: integer number; number = llGetSubString(number, 0, 9); number = -(llAbs(number)); Link to comment Share on other sites More sharing options...
SalvadorNL Posted December 5, 2021 Author Share Posted December 5, 2021 I was expecting i missed a simple FALSE option Thank you for all your Comments! Link to comment Share on other sites More sharing options...
Mollymews Posted December 5, 2021 Share Posted December 5, 2021 31 minutes ago, SalvadorNL said: I was expecting i missed a simple FALSE option KT's method above does this longhand version integer valid = (msg == (string)((integer)msg)); if (valid) ... do something ... Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted December 7, 2021 Share Posted December 7, 2021 On 12/4/2021 at 5:19 PM, SalvadorNL said: although this works, i wonder if there isn't a better/cleaner option ? LSL only has Signed 32-bit numbers, so trying to check if an integer value is outside of those bounds is impossible. Your code would work even if you removed the min/max check, at which point your code is basically the same as KT's. Sadly that's about as short as it gets. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now