|
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
|
05-28-2006 23:11
OK, this is more than a bit frustrating so it's quite possible I am missing something dumb. I'm wanting to change states conditional on a couple of things including the presence or absence of someone sitting on my object, and it's not working. I added a couple lines of debugging code in hopes the script would tell me something useful, but it's only leaving me more confused than ever.  changed(integer change) { if (change & CHANGED_LINK) { llMessageLinked(LINK_SET, 0, "ready", NULL_KEY); if (llAvatarOnSitTarget() != NULL_KEY) // if you got back on { llSay(0, "you are sitting on me"); gAnim = "sitting"; // sets a custom sitting animation llRequestPermissions(llAvatarOnSitTarget(),PERMISSION_TRIGGER_ANIMATION); } else if (llAvatarOnSitTarget() == NULL_KEY) // if you got off { llSay(0, "you are not sitting on me"); llSay(0, "running = " + (string)running); if (running = 0) { llSay(0, "changing states"); state default; // WHY IS THIS NOT HAPPENING? } else { llSay(0, "running = " + (string)running + " and you are not sitting on me but I didn't change states for some reason"); } } } }
I stand up, and here's the output: From: someone you are not sitting on me running = 0 running = 0 and you are not sitting on me but I didn't change states for some reason
The script dutifully reports whether or not I am sitting on it, but never changes back to the default state. "running" is a variable set elsewhere. The animation and everything else works fine. What am I missing? Thanks for looking.
|
|
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
|
05-28-2006 23:38
Classic Coding Mistake #4: You've got "if (running = 0)" (assignment) rather than "if (running == 0)" (comparison). I did that yesterday.
|
|
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
|
05-29-2006 00:03
From: Ordinal Malaprop Classic Coding Mistake #4: You've got "if (running = 0)" (assignment) rather than "if (running == 0)" (comparison). I did that yesterday. Thank you. I had a feeling I would end up simultaneously relieved and embarassed.  In other news, I believe that rounds out my own personal collection of Classic Coding Mistakes for the week. Time for a drink. </need for this thread>
|
|
Draco18s Majestic
Registered User
Join date: 19 Sep 2005
Posts: 2,744
|
05-29-2006 10:16
I've done the same thing in reverse (it cost me about L$200 too)... it's really embarassing when you've been coding as long as I have (or longer  ) (I've been coding for over 3 years).
|
|
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
|
05-29-2006 10:19
Oh, nobody ever stops doing it. I've been programming since I was seven and I still do it. Just one of those things.
Really, the compiler should have an option to show warnings if you have an if-condition involving an assignment... but one you can turn off, as it's useful sometimes.
|
|
Angela Salome
Registered User
Join date: 6 Oct 2005
Posts: 224
|
05-30-2006 04:39
Instead of writing your conditions this way: if (running = 0)
write them the 'reverse' way: if (0 = running)
That way the compiler picks up the assignment to a constant error, when you meant comparison to a constant.
|
|
Draco18s Majestic
Registered User
Join date: 19 Sep 2005
Posts: 2,744
|
05-30-2006 09:58
From: Ordinal Malaprop Really, the compiler should have an option to show warnings if you have an if-condition involving an assignment... but one you can turn off, as it's useful sometimes. Or a conditional that isn't inside a for(), if(), or while().
|