Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Another faulty script...

Zarma Button
Registered User
Join date: 17 Mar 2009
Posts: 7
04-05-2009 00:28
Ok... So I'm trying to make a box that ask people questions, then tells them if they are right or wrong depending on the answer they input, this what I came out with-

//Quiz Cube V1.0
default
{
touch_start(integer num_detected)
{
llInstantMessage(0, "Would you like to take the quiz? If so, please type 'yes' in the chat box. Type anything else to cancel.";);
}
}
gToucher key;
state new
{
state_entry()
{
llListen(0, "", gToucher, "";);
llSetTimerEvent(30.00);
}
listen(integer channel, string name, key id, string message) //Syntax error appears here.
{
if (message=="yes";)
{
llInstantMessage(id, name + ", your quiz well begin!";);
}
else(message=="";);
{
llInstantMessage(id, name+ ", come back next time!";);
}
state new;
touch_start(integer total_value)
{
llInstantMessage(0, "What is the chemicle compound- 'H2SO4'? You have 1 minute to answer! First word is UPPER CASE, second word is lower lase."
}
state_entry()
{
llListen(0, "", gToucher, "";);
llSetTimer(60.00);
}
llListen(integer channel, string name, key id, string message)
{
if (message=="Sulphuric acid";)
{
llInstantMessage(0, "Right answer! On to question two!";);
}
}
else(message=="";)
{
llInstantMessage(0, "Wrong, start over!";);
}
state new;
touch_start(integer total_value)
{
llInstantMessage(0, "What is the most basic expression in lsl to make an object say something? Hint: It applies to 30 meteres. Type it EXACTLY as you would if you were scripting.";);
state_entry()
{
llListen(0, "", gToucher, "";);
llSetTimer(60.00);
}
llListen(integer channel, string name, key id, string message)
{
if (message=="llSay";)
{
llInstantMessage(0, "Right! Next is question three! Final question.";);
}
state new;
touch_start(integer total_value)
{
llInstantMessage(0, "-i, the square root of -1, is really what number? *Hint, it has to be positive.";);
state_entry()
{
llListen(0, "", gToucher, "";)
llSetTimer(60.00)
}
llListen(integer channel, string name, key id, string message)
{
if (message=="1";)
{
llInstantMessage(0, "Congratuslations! You win-";);
}
else (message=="";)
{
llInstantMessage(0, "Sorry, start again.";)
}
}

I would really like if you told me what I'm doing wrong, in place of telling me a script that would actually work. This is for practice purposes, so I don't actually need the script corrected, I just need some one to tell me what I should correct, thank you.
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
04-05-2009 00:39
I'm going to repaste your code... with some attempt at proper formatting.

CODE

//Quiz Cube V1.0
default
{
touch_start(integer num_detected)
{
llInstantMessage(0, "Would you like to take the quiz? If so, please type 'yes' in
the chat box. Type anything else to cancel.");
}
}

gToucher key;

state new
{
state_entry()
{
llListen(0, "", gToucher, "");
llSetTimerEvent(30.00);
}

listen(integer channel, string name, key id, string message) //Syntax error appears here.
{
if (message=="yes")
{
llInstantMessage(id, name + ", your quiz well begin!");
}
else(message=="");

{
llInstantMessage(id, name+ ", come back next time!");
}

state new;


touch_start(integer total_value)
{
llInstantMessage(0, "What is the chemicle compound- 'H2SO4'? You have 1
minute to answer! First word is UPPER CASE, second word is lower lase."
}

state_entry()
{
llListen(0, "", gToucher, "");
llSetTimer(60.00);
}

llListen(integer channel, string name, key id, string message)
{
if (message=="Sulphuric acid")
{
llInstantMessage(0, "Right answer! On to question two!");
}
}
else(message=="")

{
llInstantMessage(0, "Wrong, start over!");
}

state new;

touch_start(integer total_value)
{
llInstantMessage(0, "What is the most basic expression in lsl to make an object
say something? Hint: It applies to 30 meteres. Type it EXACTLY as you would if you were
scripting.");

state_entry()
{
llListen(0, "", gToucher, "");
llSetTimer(60.00);
}

llListen(integer channel, string name, key id, string message)
{
if (message=="llSay")
{
llInstantMessage(0, "Right! Next is question three! Final question.");
}

state new;

touch_start(integer total_value)
{
llInstantMessage(0, "-i, the square root of -1, is really what number? *Hint, it
has to be positive.");

state_entry()
{
llListen(0, "", gToucher, "")
llSetTimer(60.00)
}

llListen(integer channel, string name, key id, string message)
{
if (message=="1")
{
llInstantMessage(0, "Congratuslations! You win-");
}
else (message=="")

{
llInstantMessage(0, "Sorry, start again.")
}
}


Now, looking at this script, I can tell why you're having problems.. it's a total disaster. Taking aside for the moment, the fact that you're totally misusing llInstantMessage.. you've got like 4 "state_entry"'s in the "new" state.

You're not closing your events, you're misusing "Else".. and to top it all off, you never even call "state new" from the default state, so you're never going to leave the default state in the first place.

You say you don't want us to fix it for you.. fine.. I won't.

But it's gibberish... and it looks like you just copied what you thought would work, and pasted it in there 5 times.

Proper formatting is your friend.. I highly suggest you invest in a tab key.

So.. beginning at the beginning.. here we go. (see you in post #2)
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura
Zarma Button
Registered User
Join date: 17 Mar 2009
Posts: 7
04-05-2009 01:01
Yar, I realize that it's total mess, and now, looking back, I can see I did miss new state;. But please, acknowledge that this is my second day using LSL, and I'm trying to practice. I don't really no proper formatting, and I'm not using tab because I'm writing it all in notepad++. If you want, I'll change the formatting to C or Java, and it will have the tabs.
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
04-05-2009 01:21
1. llInstantMessage needs two arguments, a target (UUID) and a message. You have the message, but "0" isn't an agent. So you need to tell it WHO to IM. I'd suspect you probably want to IM llDetectedkey(0).. like so.

llInstantMessage(llDetectedKey(0), "message goes here";);

2. I suppose you probably also actually wanted to store this person's key into gToucher. So we'll need to do that here, in the touch event.

gToucher = llDetectedKey(0);

3. at this point, I'd assume you'd like to jump to the "new" state. So you need to do it.

state new;

4. Obviously, you're going to need to move the gToucher variable to the top of the script, before the default state. Actually I don't know if you NEED to, but it seems tidier if you do.

5. the "new" state. Okay, we're here now.. so let's begin. state_entry is good, the listen has been opened, and you've started a timer.. great. But because you haven't used a "handle" on your listen, you won't really be able to close it. I recall there's some voodoo about state-jumping closing listens.. but with all the mono changes and whatnot, best practice is to put a handle on every listen, and close it yourself. If you don't, you run the risk of running out of listens (max 60!).. and getting one of those dreaded script errors.

As I say, you've started a timer.. which is great.. but without a timer event, why bother?

6. this first instance of a "listen" event, is actually the ONLY time you've done it right in the entire script. We'll get to that.. but let's examine what goes on in the listen event.

7. Your first "if" looks great. If the message heard on an open listen is precisely "yes" (all lower case as you've typed it here) then... IM that person (you got the key in the right place here too!) with their name plus a message! Great....

8. your use of "else" here looks as if you meant "else if". Since your test (message ==" means "is exactly equal to" you can really dispense with the else here. There's no situation in which the message will precisely equal "yes" AND "" at the same time. If you changed the word "else" to "if" here.. the script wouldn't choke... but it wouldn't work the way you want either. What you REALLY want to do here, is ditch the ";(message == "";)" part.. because you want any wrong answer to result in the "else" situation.

BTW, it's darn hard for an avatar to speak "null string".. ever.

9. again another perfect example of llInstantMessage.

10. Now you close your second "if" (or else if, or just else)... and then you trigger "state new" again. Normally this would create an endless loop, opening a new listen every time you spoke.. 59 loops and your script dies.... BUT>.......

11. you never close the "listen" event.

12. You're now starting a touch event inside the listen.. which you can't do.

13. Your use of llInstantMessage is wrong here.. you're trying to IM this "zero" fellow again.

14. your touch event is not filtered for only touches by the previously defined gToucher.

15. if someone touches during this state, it just IM's that zero guy, and does nothing else. Did you mean to have a "state new;" command after this?

16. You now have another "state entry". you can only have one of these per state. Are you trying to make a new state? you need to close the old one first. Of course, you can't have another "state new"... so you'll need to pick a new name..

17 etc.

From this point, the script goes downhill, compounding errors on top of errors. While your script may only be giving you an error somewhere at the listen event, the fact is that it's not even remotely close to functioning in any coherent manner.

triage.. since we're not allowed to fix your script for you.

1. place a "state new;" command inside your touch event in the default state.
2. make sure you're closing your functions.
3. make sure you're only using state names once. (try making states named "q1", "q2", "q3"...

honestly, there are WAY better ways to approach this project (using a strided list with the questions and answers in pairs... using a random number to choose the questions).. but the method you're using CAN work (one question per state) but you need to get ONE state working properly before copy-pasting it 5 times. Try paring it down a bit, and see if you can get "one question and one answer" working properly.

things to look up..

llListenRemove
timer - event
state
llInstantMessage
listen - event

Hope this helped.
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura
Ravanne Sullivan
Pole Dancer Extraordinair
Join date: 10 Dec 2005
Posts: 674
04-05-2009 01:30
From: Zarma Button
llInstantMessage(0, "-i, the square root of -1, is really what number? *Hint, it has to be positive.";);


Hint
Your hint is wrong. The square root of -1 is an imaginary number that really only can be expressed as "the square root of -1". What you probably meant was what is the square of -1.
_____________________
Ravanne's Dance Poles and Animations

Available at my Superstore and Showroom on Insula de Somni
http://slurl.com/secondlife/Insula de Somni/94/194/27/
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
04-05-2009 11:43
before you do anything else make sure that open braces have a closing brace at the end of whatever block of code they surround. if you count them, they should always be of equal number. code outside of event blocks will never run and will generate compile errors.
_____________________
|
| . "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...
| -