Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to check if an input goes OVER the integer limit

Derin Swenson
Registered User
Join date: 10 May 2006
Posts: 25
08-14-2007 10:52
Greetings all,

I'm a noob scripter at best, but I am createing a channel scanner for a device I use.

Nothing new there, its been done before.

I have it so that i can upon command say "input channel <channel number>" and the scanner starts listening on that channel. But before i do this I want it to check to see if i go above the 2147483647 limit or below the -2147483647 limit by accident, or in case a friend of mine who I give this too accidently inputs over the limit.

Now the wiki states that anything out of this range returns a -1. But I have seen it do different. Say you input "input channel 2147483648" just one over. It seems to make the channel negative and outputs...-2147483648.

and when I input 2147483653 it out puts -2147483643.

So basically i wanted to put in a filter but it seems to do some wonky math.

Just on a side note it works fine if you input a number that is within the channel spectrum.
Derin Swenson
Registered User
Join date: 10 May 2006
Posts: 25
08-14-2007 11:37
CODE

//this is the filter for the message

if(llDeleteSubString(message, 13,llStringLength(message)) == "input channel ")
{

//this checks to make sure they can only put in 5 channels. chancom is the
//list, and maxchancom = 5.

if(llGetListLength(chancom) >= maxchancom)
{
llOwnerSay("You have the maximun number of channels aloted to this person, please reset your channel list.");
}

else
{

if(THIS IS WHERE I WANT TO PUT THE FILTER TO CHECK AND SEE IF
THE CHANNEL IN THE COMMAND DOESN"T GO OVER LIMIT)

string searchFor = llGetSubString(message, 13, llStringLength(message));
integer index = llListFindList(chancom, [(integer)searchFor]);

if (index == -1)
{
BLAH BLAH input channels in a listen and then into a list
}

else
{
llOwnerSay( "Channel " + searchFor + " has already been designated." );
}
}
}
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
08-14-2007 11:54
Totally untested but maybe something like this would help...

CODE

integer GoodNumber (string num)
{
integer val = (integer)num;
return (string)val == num;
}


Pass in the string value and it returns TRUE if it's a valid number and FALSE if not...
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
08-14-2007 11:58
it has to do with the binary representation of an integer:
http://en.wikipedia.org/wiki/Integer_(computer_science)

For all intents and purposes though just assume that when you go below the minimum or above the maximum your value will wrap to the other side and continue to count in the same direction starting from the other end.
Derin Swenson
Registered User
Join date: 10 May 2006
Posts: 25
08-14-2007 12:39
thanks both of you will test this out tonight.
Derin Swenson
Registered User
Join date: 10 May 2006
Posts: 25
08-14-2007 12:44
another question,

i know shadow's answer would be the same (which it does seem to do).

would there be any way to do what you say Meade off of a dataserver event. Say I had a notecard they could predetermined channels they want to listen too all the time despite channel resets.

Your function wouldn't work in a dataserver event in which it already calls the data and already outputs it at the time of the event as having "wrapped" back around.

so there is not way to prevent it from wrapping it around?

I just want it to stop from wrapping and tell the individual that they have inputted an incorrect channel.
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
08-14-2007 12:48
Not sure I understand.. Wouldn't you just do...
CODE

dataserver (...)
{
string channel = ...parse channel out of dataserver info
if (!GoodNumber(channel))
{
llShout (0, "put a good number in the notecard, Bozo!");
state toast;
}
}

...or something similar?
[/quote]
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left