Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Syntax error

ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
03-31-2008 15:06
I keep getting a syntax error at "integer index" in the 4th line of text. This looks like the wiki example I referenced, can anyone else see what the problem is here?


CODE

//Script ramdomly says stuff it every 40-60 seconds or when touched
//Turn chat function on or off with "/1 Chat On" or "/1 Chat Off"

list myList = ["A","B","C","D","E","F"];// list of phrases the sript will choose from.
integer index = (integer)llFrand(6.0); // number must be number of phrases above.

fPlayRandom() //this is a function written to hold the llWhisper call
{
llWhisper(0,llList2String(mylist,index));
} // llWhisper call placed inside of a function which
//can be called by the touch event or the timer.
//This randomly picks one of the phrases to say

default
{
state_entry()
{
fPlayRandom(); // calls for the function to run
llListen(1,"","",""); //anyone can change it.
llSetTimerEvent(llFrand(40)+20); // sets time for timer() below, random time between 40-60 seconds
}
////////////////////////////////////////////////////////////////////////////
on_rez(integer rez_num)
{
llResetScript();
}
////////////////////////////////////////////////////////////////////////////
listen(integer chan, string name, key id, string msg)
{
if(msg=="chaton")
{
llWhisper(0, "Chat On");
llSetTimerEvent(llFrand(40)+20);
return;
}
if(msg=="chatoff")
{
llWhisper(0, "Chat Off");
llSetTimerEvent(llFrand(0);
return;

}
}
////////////////////////////////////////////////////////////////////////////


touch_start(integer total_number) // randomly will play one of those sounds each time you touch it
{
fPlayRandom();// calls for the function to run
}
////////////////////////////////////////////////////////////////////////////
timer() //plays as frequently as dictated by the llSetTimer call in state_entry

{
fPlayRandom();// calls for the function to run
}
////////////////////////////////////////////////////////////////////////////
}

_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo
Day Oh
Registered User
Join date: 3 Feb 2007
Posts: 1,257
03-31-2008 15:20
Ah, you can't have function calls or math and stuff in global variables. The values are baked into the compiled binary as are chocolate chips into a cookie.
_____________________
ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
03-31-2008 17:06
Ahh my mistake thinking that had to be a global variable. Moving it to the function seemed to work OK.

I tried debugging the script on http://w-hat.com/run_lslint and it also said

ERROR:: ( 5, 17): Global initialize must be constant.
_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
03-31-2008 19:24
CODE
list myList =["A", "B", "C", "D", "E", "F"];
integer index;

fPlayRandom()
{
index = (integer) llFrand(6.0);
llWhisper(0, llList2String(myList, index));
}

default {
state_entry() {
fPlayRandom();
llListen(1, "", "", "");
llSetTimerEvent(llFrand(40) + 20);
}

on_rez(integer rez_num) {
llResetScript();
}

listen(integer chan, string name, key id, string msg) {
if (msg == "chaton") {
llWhisper(0, "Chat On");
fPlayRandom();
llSetTimerEvent(llFrand(40) + 20);
return;
}
if (msg == "chatoff") {
llWhisper(0, "Chat Off");
llSetTimerEvent(llFrand(0));
return;
}
}
touch_start(integer total_number) {
fPlayRandom();
}
timer() {
fPlayRandom();
}
}
_____________________
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
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
04-01-2008 11:10
Heh. Here's a little LSL "Design Pattern" I use ALL the time:

CODE

type1 variable1;
type2 variable2;

integer initialized = FALSE;
init()
{
if (initialized)
{
return;
}
initialized = TRUE;

variable1 = computation1;
variable2 = computation2;
}

default
{
state_entry()
{
init();

...
}

...
}

...


It would be really nice if LL simply made this the exact semantics of any compultations done in global variable initialization, but oh well. Maybe someone'll create a JIRA for it that'll be ignored for the next several years.