Validating Said is a integer....
|
|
Saladin Nightfire
Scripter for HIRE
Join date: 6 Jan 2008
Posts: 20
|
02-12-2008 12:38
Validating Said is a integer....within the valid scope of things. Integers can't be larger than 2,147,483,647 or -2,147,483,647 But HOW do i validate them ? listen( integer channel, string name, key id, string msg ) { integer msg = (integer)msg; if ( msg >= -2147483647 & msg <= 2147483647) { llSay(0 , "It works"); } else { llSay(0, "Not right at all"); }
But it is not working... i always says it works:( sooo please can someone assit me in this would be greatly appreciated..:)
|
|
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
|
02-12-2008 12:40
|
|
Atashi Toshihiko
Frequently Befuddled
Join date: 7 Dec 2006
Posts: 1,423
|
02-12-2008 12:42
When you declare integer msg = (integer)msg; I believe LSL is declaring a new value for msg and the default is 0... it doesn't know whigh msg you want to use, since you've used the variable twice.
Try integer number = (integer)msg; instead, or really any other variable name but msg.
For your own debugging you could also have it read it back to you: llSay(0, "the integer is " + (string)number);
Also note that if the msg captured in the listen cannot be made into an integer it will probably get made into a zero.
-Atashi
_____________________
Visit Atashi's Art and Oddities Store and the Waikiti Motor Works at beautiful Waikiti.
|
|
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
|
02-12-2008 12:45
From: Atashi Toshihiko Also note that if the msg captured in the listen cannot be made into an integer it will probably get made into a zero Which would pass the "msg >= -2147483647 & msg <= 2147483647" test in the original post, yeah... Something to keep in mind.
|
|
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
|
02-12-2008 12:47
Well, phooey... Reviewing the link I posted earlier, it also doesn't handle negative numbers 
|
|
Saladin Nightfire
Scripter for HIRE
Join date: 6 Jan 2008
Posts: 20
|
02-12-2008 12:54
ok i will try these right now to see if they work.. i am in game now working on them 
|
|
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
|
02-12-2008 13:00
How about casting the string to an int then back to a string and comparing that with the original string?
|
|
Saladin Nightfire
Scripter for HIRE
Join date: 6 Jan 2008
Posts: 20
|
02-12-2008 13:04
default { state_entry() { llListen( 0, "", NULL_KEY, "" ); } listen( integer channel, string name, key id, string msg ) { string data = msg; if((llParseString2List(data, ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], []) == []) && (data != "")) { llOwnerSay("Integer"); } else { llOwnerSay("Not An Integer"); } } }
but 2 things.. 1. it don't accomidate neg numbers 2. only goes to 7 digits:(
i kinda at a loss:(
|
|
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
|
02-12-2008 13:13
Try.. listen( integer channel, string name, key id, string msg ) { integer i = (integer)msg; if ((string)i != msg) { // not an integer
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
02-12-2008 13:25
So using Sindy's to check if it is something else then an integer and also checking if it is between the range you would end up with: default { state_entry() { llListen(0, "", NULL_KEY, ""); }
listen(integer channel, string name, key id, string msg) { integer i = (integer)msg; if ((string)i == msg && (integer) msg >= -2147483647 && (integer) msg <= 2147483647){ llSay(0, "It works"); } else { llSay(0, "Not right at all"); } } }Say "-42" and it will answer with "It works". -42.5 will return "Not right at all" outside of range will return "Not right at all" and finally "cat" will return "Not right at all"
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Saladin Nightfire
Scripter for HIRE
Join date: 6 Jan 2008
Posts: 20
|
02-12-2008 13:32
well sindy it worked and i thank you ... default { state_entry() { llListen( 0, "", NULL_KEY, "" ); } listen( integer channel, string name, key id, string msg ) { integer i = (integer)msg; if ((string)i != msg) { llOwnerSay("not integer"); } else { llOwnerSay("yes integer"); } } }
That is the final result and works for 10 digits and Neg numbers... thnx for all the help ...
|
|
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
|
02-12-2008 13:45
You're welcome, Saladin! From: Jesse Barnett So using Sindy's to check if it is something else then an integer and also checking if it is between the range... Not in-world where I can test but I was assuming that if you fed it something outside the range of a signed int, the integer cast would give you back a zero and fail the test. Still have the script? Now I'm all curious what it'll say for 3 billion.. 
|
|
Saladin Nightfire
Scripter for HIRE
Join date: 6 Jan 2008
Posts: 20
|
02-12-2008 14:28
Integers can't be larger than 2,147,483,647 and it won't work above that and it works on the negative side sindy so ur all good there  GREAT work... it did what i wanted... i was tring to make sure there was a number that i could pick and put to a data for a channel that the person wanted but in the limits of that and the fact that they could only pick a number not a word or anything which would make the whole system fail 
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
02-12-2008 14:40
From: Sindy Tsure You're welcome, Saladin! Not in-world where I can test but I was assuming that if you fed it something outside the range of a signed int, the integer cast would give you back a zero and fail the test. Still have the script? Now I'm all curious what it'll say for 3 billion..  Ah nice, so what you posted is all that is necessary adn you don't need to check against the range also. LSL1 -2147483648 returns: "It works" -2147483649 returns: "Not right at all" Bad news is that if you go outside of range in MONO it will throw and error. Time for another jira entry: MONO -2147483648 returns: "It works" -2147483649 returns: [14:35] Object: System.OverflowException: Value too large or too small. at System.Int32.Parse (System.String s, NumberStyles style, IFormatProvider fp) [0x00000] at System.Int32.Parse (System.String s, NumberStyles style) [0x00000] at LindenLab.SecondLife.LslRunTime.StringToInt (System.String s) [0x00000] at LSL_711be307_a5a2_fc31_8645_201ea63b200a.defaultchat (Int32 channel, System.String name, System.String id, System.String msg) [0x00000] at LSL_711be307_a5a2_fc31_8645_201ea63b200adefaultchatFrame.ResumeVoid () [0x00000] at LindenLab.SecondLife.UThread.UThread.Run () [0x00000] at LindenLab.SecondLife.Script.Run (ScriptEvent evt) [0x00000]
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
02-12-2008 16:22
ahahah no bounds checking in mono typecasts? I await the jira to vote on.
beware using the method
i = (integer)msg if ((string)i == msg)
if there are any extraneous spaces in msg, they will be dropped when converting to integer, and then the comparison will still fail on valid data. not sure if any other characters would be ignored in this fashion on conversion to integer, but it's something to be aware of.
_____________________
| | . "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... | - 
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
02-12-2008 16:35
Regular expressions would make parsing of large integers (or floating point numbers, or vectors, lists, commands, web pages, whatever) MUCH easier. Go vote for https://jira.secondlife.com/browse/SVC-790 if you haven't, and help expand our toolset enourmously with only the addition of a couple new functions.
|
|
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
|
02-12-2008 17:10
From: Jesse Barnett Bad news is that if you go outside of range in MONO it will throw and error. /me guesses they'll fix that before releasing MONO scripts into the wild.. While I'm guessing, I'll guess that trying to do (integer)"blahblahblah" will also throw some kind of invalid cast exception.
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
02-12-2008 17:24
From: Void Singer ahahah no bounds checking in mono typecasts? I await the jira to vote on. http://jira.secondlife.com/browse/SVC-1530
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|