Else.. If Problem
|
|
Klaire Larnia
Learner, be gentle....
Join date: 2 Jun 2008
Posts: 41
|
05-20-2009 10:41
Hi I am new to scripting and need to ask a newbie question sadly I have a basic door script and am adding basic security to help me learn things. I have this but it will not complie: From: someone doorlock(string whoisit)
{
if ( whoisit == “Klaire Larnia” ); ENT = 1; } else if ( whoisit == “Lekara Kelberry” ); { ENT = 1; } else { ENT = 0; }
}
I get a syntax error on the first IF statement but I do not know why. I have defined it as a string in the "doorlock" statement, and the string it is checking is in quotes as I would expect. I am guesing it is the space causing the problem. But as I checking an AV name (gained with the command "string AvName = llKey2Name((key)message)", I am not sure how to over come this. Can someone give me a hint on where the problem lies and how I may overcome it to make this work. I do not want the answer, just a gentle shove in the right direction on where to look for it as I am lost  Thanks Klaire
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
05-20-2009 10:44
Yer missing one { thingie and need to remove the ';' at the end of the 'if' lines.. Like this: doorlock(string whoisit) { if ( whoisit == “Klaire Larnia” ) { ENT = 1; } else if ( whoisit == “Lekara Kelberry” ) { ENT = 1; } else { ENT = 0; } }
_____________________
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
|
|
Klaire Larnia
Learner, be gentle....
Join date: 2 Jun 2008
Posts: 41
|
05-20-2009 11:02
Sorry to ask such a dumb question there, I am glad it was something simple.
Thank you so much! Klaire
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
05-20-2009 11:11
No worries. Everybody's new sometime. 
_____________________
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
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-20-2009 13:20
try writing you control statements like this. if (stuff) { //-- do stuff }
this will help prevent you from accidentally adding ; (and makes finding missing ones easier because you can skip lines ending with { , but it makes brace matching a mite harder, so don't forget to indent properly to avoid that.
_____________________
| | . "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... | - 
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
05-20-2009 13:23
Ack!! Noooo!!!
Open & closing braces should go at the same indentation level.
And tabs should be used! Tabs!!! Not spaces!!!
/me glares at Void.
_____________________
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
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
05-20-2009 13:52
From: Meade Paravane Open & closing braces should go at the same indentation level. Ritchie Style was good enough for Dennis Ritchie, and that's good enough for me!
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
05-20-2009 14:12
Uh huh.. K&R probably used that style because code was spit out of line printers or on crappy 24-line displays back then and visual real estate was at more of a premium...
Klaire, use whatever makes the code easier for you to read. In my totally unbiased opinion, you can chose to put them at the same spacing which makes blocks of code much easier to see at a glance or you can be like other people that are stuck 30 years in the past and put them at totally visually-unrelated indentation levels. The important bit is to be consistant to whatever style you chose - it might sound silly but will make your life easier (especially if they're at the same indent level).
_____________________
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
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
05-20-2009 14:44
From: Meade Paravane a bunch of silly words Give me K&R or give me death!  I love code beautification threads. But yes you were right with at lease the first part here: From: Meade Paravane The important bit is to be consistant to whatever style you chose - it might sound silly but will make your life easier
_____________________
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
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
05-20-2009 14:56
From: Meade Paravane Uh huh.. K&R probably used that style because code was spit out of line printers or on crappy 24-line displays back then and visual real estate was at more of a premium... That's not what Dennis told me. I use K&R style because putting the brace in the next line breaks up the association between the line and the body of the loop, for short blocks. For longer blocks, it doesn't matter. Since vi has has "showmatch" almost as long as I've been using it, I *can't* lose the brace, and if you can't see your blocks at a glance you're screwing up your indentation.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-20-2009 15:03
lol I did point out merits of catching mistakes for both styles  (and damnit I'd bee happy to use tabs on this ... forum, if I could set them, and better still if the ... software would treat them consistently. sadly, it doesn't, notepad isn't settable (I need to reload NoteTab) and the stupid SL editor converts them to spaces... just be happy I used four instead of two as is my want = P )
_____________________
| | . "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... | - 
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
05-20-2009 15:13
From: Void Singer just be happy I used four instead of two as is my want = P ) That's "wont", an obsolete term meaning "habit" that is completely extinguished except in this charming anachronism. And it is charming. 
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-20-2009 16:27
ah but it's a variant of want, so still poetically relevant (I love tossing odd old phrases about)
_____________________
| | . "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... | - 
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
05-20-2009 17:28
From: Void Singer ah but it's a variant of want, so still poetically relevant (I love tossing odd old phrases about) If you put two etymologists in a room armed with paper-knives, and asked them whether wont and want were related, only one would come out alive.
|
|
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
|
05-20-2009 18:44
From: Argent Stonecutter If you put two etymologists in a room armed with paper-knives, and asked them whether wont and want were related, only one would come out alive. I don't care what bug scientists do with their time. I prefer the look of.. if (test == TRUE) // if the test passes { do (stuff); } else // the test failed { do (other stuff); }
I like the ability to comment the if's so I know where I'm at when I go back to a script a year later. I also like the symmetry of the opening and closing braces. But I also come from years of web design and handcoded html.. so symmetrical tabbing is more comfortable for me.
_____________________
 ● Inworld Store: http://slurl.eclectic-randomness.com ● Website: http://www.eclectic-randomness.com ● Twitter: @WinterVentura
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
05-20-2009 19:42
From: Argent Stonecutter If you put two etymologists in a room armed with paper-knives, and asked them whether wont and want were related, only one would come out alive. Ya'll are just lucky that you only see my typed words. I was born and raised down in Texas. I have been living up North for about 15 years and I am still trying to teach everyone up here how to talk right. I have already given up on trying to teach hedgehogs and cyborg princesses how to beautify their code correctly thou OP, In case you are wondering what in the heck we are talking about................ When you deal with code a few hours a day, it makes it much easier to read and troubleshoot if it is formatted in the particular style you are used to. Unfortunately there are a handful of different styles in use and the only right one seems to be the one the user is used to. It is an endless source of playful bickering here whenever the subject is broached. We are not actually mad at each other and I have no ill feelings towards those that do not use K&R, just pity 
_____________________
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
|
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
05-20-2009 22:15
From: Meade Paravane Ack!! Noooo!!!
Open & closing braces should go at the same indentation level.
And tabs should be used! Tabs!!! Not spaces!!!
/me glares at Void. I'm with you Meade! Same indentation for same level makes sense, and stuff easier to debug. Void, you know I know you're a good coder, but ugh... I hate that 'lets be confusing for no reason' method !
_____________________
My tutes http://www.youtube.com/johanlaurasia
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
05-20-2009 23:24
From: Jesse Barnett OP, In case you are wondering what in the heck we are talking about................ When you deal with code a few hours a day, it makes it much easier to read and troubleshoot if it is formatted in the particular style you are used to.
It's easier to read and troubleshoot it if it's all formatted in the same style. I use whatever the style of the project is. Given a choice, though, I go with the same modified K&R style that you find in the BSD and Linux kernels. It's often called "Linux Style", and is closer to what K&R actually used than what most people seem to call "K&R style" because most people forget that K&R didn't have function prototypes so function definitions were always multi-line.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-21-2009 01:05
From: Winter Ventura I don't care what bug scientists do with their time. I prefer the look of.. if (test == TRUE) // if the test passes { do (stuff); } else // the test failed { do (other stuff); }
I like the ability to comment the if's so I know where I'm at when I go back to a script a year later. I also like the symmetry of the opening and closing braces. But I also come from years of web design and handcoded html.. so symmetrical tabbing is more comfortable for me. ety-, not ento- =) and you could still comment after a bracket in 1TBS, and it works wonderfully in web context with indented attribute lists within a tag. I only suggested 1TBS to OP for the possibility of more easily tracking one sort of error [missing | extraneous] semicolons. if OP had been struggling with brace matching errors, I'd have suggested the Allman style. I hate the mixed style formattings (yet I use mixed style variable prefixes), or the one that overlap on a new line, or indent braces (either halfway or to the same depth as the interior code.)
_____________________
| | . "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... | - 
|
|
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
|
05-21-2009 02:18
lol I really try hard not to use ugly code, but I have to admit, I have scripts out there with a plethora of styles all in the same script. I type really fast and sometimes it comes out ugly, but compiles, and if it compiles, I don't always go back and make it right 
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
05-21-2009 04:10
From: Void Singer I hate the mixed style formattings (yet I use mixed style variable prefixes),
Oh, can I hate on hungarian notation now? Can I, huh? From: someone or the one that overlap on a new line, or indent braces (either halfway or to the same depth as the interior code.) We don't need THAT kind of language in this place. Ewww.
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
05-21-2009 05:26
From: Argent Stonecutter Oh, can I hate on hungarian notation now? Can I, huh? Reverse Polish Notation is soooo cool  From: Argent Stonecutter We don't need THAT kind of language in this place. Ewww. You can always resort to Phyton, where indentation is mandatory and brackets are wasted(in the sense they are used in LSL, C etc.)
_____________________
From Studio Dora
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
05-21-2009 06:32
From: Dora Gustafson Reverse Polish Notation is soooo cool  You like Yoda can program, if you Forth learn. hUngarian nOtation iS sOmething cOmpletely dIfferent. From: someone You can always resort to Phyton, where indentation is mandatory and brackets are wasted(in the sense they are used in LSL, C etc.) Python is hateful, evil, rude, nasty, and completely misguided. Programs communicate to two audiences, humans and compilers. Indentation is too useful as a mechanism to communicate to humans, in ways that are irrelevant to compilers, and Python makes that completely impossible.
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
05-21-2009 08:01
From: Argent Stonecutter Python is hateful, evil, rude, nasty, and completely misguided.. Well, we can agree on some things, I guess.
_____________________
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
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
05-21-2009 08:14
From: Meade Paravane Well, we can agree on some things, I guess. Hedgehogs aren't food, that's another. (too spiky)
|