Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

What causes a math error?

Imago Aeon
Animation Designer
Join date: 23 Oct 2007
Posts: 65
12-26-2008 11:32
I've read all over that it's caused by trying to split a number and it gives you a fraction. I've been trying to fix this script for a day or so (I get bored) So, if anyone has any insight in to what's causing it any help would be appreciated. (I found it because I read a post asking for one and now I can't put it away. *laughs* Even though I probably wouldn't use it, but it's fun to figure things out.)

CODE


integer rentperiod = 7;
integer rentcost;
string rentinfonotecard = "_RentInformation_";
string rentadtexture = "_RentAdTexture_";
string rentscript;
string rentboardowner;
integer amountpaid = 0;

key renterkey;
string rentername;
integer countdown = 0;

string ItemNotecard="";
string ItemLandmark="";
string ItemObject="";
string ItemTexture="";

string Day2Left = "No";
string Day1Left = "No";

string tstring;

delnonowneritems()
{
integer x;
for (x = llGetInventoryNumber(INVENTORY_ALL) ; x >= 0 ; x--)
{
tstring = llGetInventoryName(INVENTORY_ALL, x);
if ((tstring != rentinfonotecard) && (tstring != rentadtexture) && (tstring != rentscript) && (tstring != ""))
{
llRemoveInventory(tstring);
}
}
}

default
{
state_entry()
{
// llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);
rentboardowner = llKey2Name(llGetOwner());
state init;
}
}

state init
{ //Initialize
state_entry()
{
amountpaid = 0;
rentername = "";
renterkey = NULL_KEY;
countdown = 0;
ItemNotecard="";
ItemLandmark="";
ItemObject="";
ItemTexture="";
Day2Left = "No";
Day1Left = "No";
rentcost = (integer)llGetObjectDesc();
rentscript = llGetScriptName();
llSetTexture(rentadtexture, 0);
delnonowneritems();
state waitforrenter;
}
on_rez(integer i) {llResetScript();}
}

state waitforrenter
{ //Accept payment or dispense "about me" notecard
state_entry()
{
llInstantMessage(llGetOwner(), "Ready to rent...");
llSetPayPrice(PAY_DEFAULT, [PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT]);
// llSetPayPrice(PAY_HIDE, [1, (rentcost*2), (rentcost*3), (rentcost*4)]);
}

touch_start(integer num)
{
if (llGetInventoryType(rentinfonotecard) == INVENTORY_NONE)
{
llInstantMessage(llDetectedKey(0), "Sorry, I don't have instructions to dispense. Please notify "+rentboardowner);
return;
}
integer perm_mask = llGetInventoryPermMask(rentinfonotecard, MASK_OWNER);
if(perm_mask & PERM_COPY)
{
llGiveInventory(llDetectedKey(0), rentinfonotecard);
}
else
{
llInstantMessage(llDetectedKey(0), "Sorry, I don't have permission to dispense instructions. Please notify "+rentboardowner);
}
}

money(key id, integer amount)
{
if ((amount/rentcost) != (integer)(amount/rentcost))
{
llGiveMoney(id, amount);
llInstantMessage(id, "Refunding, the cost to rent this per week is L$"+(string)rentcost);
return;
}
countdown = (amount / rentcost) * 7 * 24 * 60 * 60; //Seven days in a week, 24 hours in a day, 60 mins in an hour, 60 seconds in a min
llInstantMessage(id, "Thank You "+llKey2Name(id)+", you now have "+(string)(countdown/60/60/24)+" days left on your rent");
renterkey = id;
rentername = llKey2Name(renterkey);
amountpaid = amount;
state acceptitems;
}

link_message(integer sender_num, integer num, string str, key id)
{
if (str == "reset")
{
llInstantMessage(llGetOwner(), "Resetting, please wait...");
llResetScript();
}
}

on_rez(integer i) {llResetScript();}
}

state acceptitems
{ //CTRL drag items into contents
state_entry()
{
llSetTimerEvent(30 * 60);
llAllowInventoryDrop(TRUE);
llInstantMessage(renterkey, "Please hold down the CTRL key and drag an image, notecard, and landmark onto me. Click me when finished to begin displaying your advertisement");
}

timer()
{
llInstantMessage(renterkey, "Did not accept items and start advertisement within 30 minutes, issuing refund");
llGiveMoney(renterkey, amountpaid);
state init;
}

link_message(integer sender_num, integer num, string str, key id)
{
if (str == "reset")
{
llInstantMessage(llGetOwner(), "Resetting, please wait...");
llResetScript();
}
}

touch_start(integer num)
{
if (llDetectedKey(0) != renterkey)
{
return;
}

llInstantMessage(renterkey, "Preparing your advertisement...");

if (ItemTexture != "")
{ llInstantMessage(renterkey, "Texture: "+ItemTexture); }
else
{ llInstantMessage(renterkey, "Texture: <none>"); }
if (ItemNotecard != "")
{ llInstantMessage(renterkey, "Notecard: "+ItemNotecard); }
else
{ llInstantMessage(renterkey, "Notecard: <none>"); }
if (ItemObject != "")
{ llInstantMessage(renterkey, "Object: "+ItemObject); }
else
{ llInstantMessage(renterkey, "Object: <none>"); }
if (ItemLandmark != "")
{ llInstantMessage(renterkey, "Landmark: "+ItemLandmark); }
else
{ llInstantMessage(renterkey, "Landmark: <none>"); }

if ((ItemTexture == "") || (ItemNotecard == "") || (ItemObject == "") || (ItemLandmark == ""))
if ((ItemTexture == "") || (ItemNotecard == "") || (ItemLandmark == ""))
{
llInstantMessage(renterkey, "One of each item is required to start renting this board");
return;
}

llListen(50, "", renterkey, "");
llDialog(renterkey, "Are you ready?", ["Yes", "No"], 50);
}

listen(integer channel, string name, key id, string message)
{
if (channel != 50)
{
return;
}
if (message == "Yes")
{
state dispense;
}
}

changed(integer mask)
{
integer i;
for (i=0 ; i<llGetInventoryNumber(INVENTORY_ALL) ; i++)
{
string tstring = llGetInventoryName(INVENTORY_ALL, i);
if ((tstring != rentadtexture) && (tstring != rentinfonotecard) && (tstring != rentscript))
{
if (llGetInventoryPermMask(tstring, MASK_NEXT) & PERM_COPY)
{}
else
{
llInstantMessage(renterkey, "I do not have COPY permission to distribute "+tstring);
llGiveInventory(renterkey, tstring);
return;
}
}
}

if(mask & (CHANGED_ALLOWED_DROP | CHANGED_INVENTORY))
{
integer i;
for (i=0 ; i<llGetInventoryNumber(INVENTORY_TEXTURE) ; i++)
{
string tstring = llGetInventoryName(INVENTORY_TEXTURE, i);
if ((tstring != ItemTexture) && (tstring != rentadtexture) && (ItemTexture != ""))
{
llInstantMessage(renterkey, "Replacing "+ItemTexture+" with "+tstring);
llRemoveInventory(ItemTexture);
ItemTexture=tstring;
return;
}
if ((tstring != rentadtexture) && (ItemTexture == ""))
{
llInstantMessage(renterkey, "Recieved Texture: "+tstring);
ItemTexture=tstring;
return;
}
}

for (i=0 ; i<llGetInventoryNumber(INVENTORY_NOTECARD) ; i++)
{
string tstring = llGetInventoryName(INVENTORY_NOTECARD, i);
if ((tstring != ItemNotecard) && (tstring != rentinfonotecard) && (ItemNotecard != ""))
{
llInstantMessage(renterkey, "Replacing "+ItemNotecard+" with "+tstring);
llRemoveInventory(ItemNotecard);
ItemNotecard=tstring;
return;
}
if ((tstring != rentinfonotecard) && (ItemNotecard == ""))
{
llInstantMessage(renterkey, "Recieved Notecard: "+tstring);
ItemNotecard=tstring;
return;
}
}

for (i=0 ; i<llGetInventoryNumber(INVENTORY_OBJECT) ; i++)
{
string tstring = llGetInventoryName(INVENTORY_OBJECT, i);
if ((tstring != ItemObject) && (ItemObject != ""))
{
llInstantMessage(renterkey, "Replacing "+ItemObject+" with "+tstring);
llRemoveInventory(ItemObject);
ItemObject=tstring;
return;
}
if (ItemObject == "")
{
string tstring = llGetInventoryName(INVENTORY_OBJECT, i);
llInstantMessage(renterkey, "Recieved Object: "+tstring);
ItemObject=tstring;
return;
}
}

for (i=0 ; i<llGetInventoryNumber(INVENTORY_LANDMARK) ; i++)
{
string tstring = llGetInventoryName(INVENTORY_LANDMARK, i);
if ((tstring != ItemLandmark) && (ItemLandmark != ""))
{
llInstantMessage(renterkey, "Replacing "+ItemLandmark+" with "+tstring);
llRemoveInventory(ItemLandmark);
ItemLandmark=tstring;
return;
}
if (ItemLandmark == "")
{
string tstring = llGetInventoryName(INVENTORY_LANDMARK, i);
llInstantMessage(renterkey, "Recieved Landmark: "+tstring);
ItemLandmark=tstring;
return;
}
}
}
}

on_rez(integer i) {llResetScript();}
}

state dispense
{ //Also allows lease extension by either renter or owner
state_entry()
{
if (ItemTexture != "")
{
llSetTexture(ItemTexture, 0);
}
llInstantMessage(renterkey, "Your advertisement has now began...");
llSetTimerEvent(60);

llSetPayPrice(PAY_HIDE, [0, 0, 0, 0]);
if (countdown <= (3 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, 0, 0, 0]);
}
if (countdown <= (2 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, (rentcost*2), 0, 0]);
}
if (countdown <= (1 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, (rentcost*2), (rentcost*3), 0]);
}
}

link_message(integer sender_num, integer num, string str, key id)
{
if (str == "reset")
{
llInstantMessage(llGetOwner(), "Resetting, please wait...");
llResetScript();
}
}

money(key id, integer amount)
{
if ((amount/rentcost) != (integer)(amount/rentcost))
{
llGiveMoney(id, amount);
llInstantMessage(id, "Refunding, the cost to rent this per week is L$"+(string)rentcost);
return;
}
if ((id != llGetOwner()) && (id != renterkey))
{
llGiveMoney(id, amount);
llInstantMessage(id, "Only the owner or current renter can extend the rental period. Issuing refund");
return;
}
countdown += (amount / rentcost) * 7 * 24 * 60 * 60; //Seven days in a week, 24 hours in a day, 60 mins in an hour, 60 seconds in a min
llInstantMessage(id, "Thank You "+llKey2Name(id)+", you now have "+(string)(countdown/60/60/24)+" days left on your rent");

llSetPayPrice(PAY_HIDE, [0, 0, 0, 0]);
if (countdown <= (3 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, 0, 0, 0]);
}
if (countdown <= (2 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, (rentcost*2), 0, 0]);
}
if (countdown <= (1 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, (rentcost*2), (rentcost*3), 0]);
}

}

touch_start(integer num)
{
if (ItemNotecard != "")
{
llGiveInventory(llDetectedKey(0), ItemNotecard);
}
if (ItemObject != "")
{
llGiveInventory(llDetectedKey(0), ItemObject);
}
if (ItemLandmark != "")
{
llGiveInventory(llDetectedKey(0), ItemLandmark);
}
}

timer()
{
countdown -= 60;

llSetPayPrice(PAY_HIDE, [0, 0, 0, 0]);
if (countdown <= (3 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, 0, 0, 0]);
}
if (countdown <= (2 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, (rentcost*2), 0, 0]);
}
if (countdown <= (1 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, (rentcost*2), (rentcost*3), 0]);
}

if ((Day2Left == "No") && (countdown < (3600 * 48)))
{
Day2Left="Yes";
llInstantMessage(renterkey, "You have less than two days left on your rent at "+(string)(llGetParcelDetails(llGetPos(), [PARCEL_DETAILS_NAME])));
return;
}
if ((Day1Left == "No") && (countdown < (3600 * 24)))
{
Day1Left="Yes";
llInstantMessage(renterkey, "You have less than one day left on your rent at "+(string)(llGetParcelDetails(llGetPos(), [PARCEL_DETAILS_NAME])));
return;
}
if (countdown < 0 )
{
llInstantMessage(renterkey, "Your rent at "+(string)(llGetParcelDetails(llGetPos(), [PARCEL_DETAILS_NAME]))+" has expired.");
state init;
}
}

on_rez(integer i) {
llResetScript();
}
}
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
12-26-2008 11:43
One thing I notice is that rentcost is being set from the object description, and there doesn't seem to be any checking going on there. Simple division by zero problem?
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
12-26-2008 11:46
From: Imago Aeon
I've read all over that it's caused by trying to split a number and it gives you a fraction. I've been trying to fix this script for a day or so (I get bored)

Sorry to inform you, I got bored too, so very bored, so bored I am not even looking to see if you added some clue in the multi page attached code:(
_____________________
From Studio Dora
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
12-26-2008 11:51
Can you tell where the error occurs?
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
12-26-2008 12:46
The only non-constant you divide by with either '/' or '%' s 'rentcost'. The only math error I know of in LSL is divide-by-zero. I'd guess the same as the folks above: somehow you have a zero 'rentcost' in one of the places you divide.
Imago Aeon
Animation Designer
Join date: 23 Oct 2007
Posts: 65
12-26-2008 13:01
From: Dora Gustafson
Sorry to inform you, I got bored too, so very bored, so bored I am not even looking to see if you added some clue in the multi page attached code:(


Well, that's the sad thing. It wasn't commented, but there's no need to be so very rude about it.
Imago Aeon
Animation Designer
Join date: 23 Oct 2007
Posts: 65
12-26-2008 13:04
And to everyone else.

Yeah, I'm looking for the error. It only happens after you pay the object. So, it says Math Error after you pay it and quits. So, I'm guessing it's somewhere in there. I'm going to do some more tests with it and then post the finished fixed code so that everyone can enjoy it.

(I guess some people don't like long pages of code, but if the code is large I'd rather put it in to one post rather then keep posting a bunch of little posts with the same code and having a newbie who's testing code not grab all the code, and then post it somewhere else as not working.)
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
12-26-2008 13:14
Can you add a bunch of llOwnerSay statements to help figure out where the error occurs and what the values of variables are prior to the error?
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-
Imago Aeon
Animation Designer
Join date: 23 Oct 2007
Posts: 65
12-26-2008 13:26
From: SuezanneC Baskerville
Can you add a bunch of llOwnerSay statements to help figure out where the error occurs and what the values of variables are prior to the error?


Sorry about that. I did get it working. It was in the obj description like another user mentioned. (I did miss that.) So the math error doesn't happen now. I guess it was trying to divide by zero.

It's a nice script and I just hope someone can get some use out of it. I don't know who made it only that it was in my inventory for a long time so if someone knows who made it please credit the creator.

Anyhow, thanks to everyone for their help. (I'm not really a scripter. I just like cobbling things together when I need stuff.)
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
12-26-2008 13:31
So..

Is the script shown the defective one or the corrected one?
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-26-2008 18:48
From: SuezanneC Baskerville
So..

Is the script shown the defective one or the corrected one?

technically both... it'd work fine with a set description...

must remember to validate inputs
_____________________
|
| . "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...
| -
Ollj Oh
Registered User
Join date: 28 Aug 2007
Posts: 522
12-26-2008 20:18
sicne youre not using llPow(higher,toohigh) you must be dividing by 0 .
but you only divide by "/rentcost" and that is rentcost=(integer)llGetObjectDesc(); set only once in the initialisation.
so there is your error?
Nicolette Beebe
Registered User
Join date: 8 Feb 2007
Posts: 18
12-27-2008 04:34
Is it all error error or a math error?

If you are using 2 type with math lsl will often not give you the desired results. An example would be a float divided by a integer or vice versa. Try typecasting all your variables im the equation to one type then do the math.

Sorry for not checking myself but that script is entirely too long :P