Page 1 of 1

Unexpected declaration

PostPosted: Sun Mar 02, 2008 8:52 pm
by edh
I have a global integer called "canKick"

In my drawActor, I have the following
Code: Select all
if (canKick == 1)
    {
        if (rand(10) <= 1)
            {
                canKick = 0;
                Actor* ball = CreateActor("ball", "rolling", "(none)", "(none)", 0, 0, false);
                ball->yvelocity = 5 + rand(10);

            }
 
    }


When I try to save, I get "Error line 6: Unexpected declaration canKick"

If I ignore the error, I cannot enter Game Mode, it complains again about the script.

If I move canKick = 0, like this, there is no problem
Code: Select all
if (canKick == 1)
    {
        if (rand(10) <= 1)
            {
               
                Actor* ball = CreateActor("ball", "rolling", "(none)", "(none)", 0, 0, false);
                canKick = 0;
                ball->yvelocity = 5 + rand(10);

            }
 
    }


Looks like a parsing error in the script editor, maybe?

Re: Unexpected declaration

PostPosted: Sun Mar 02, 2008 9:02 pm
by makslane
The problem is the Actor* ball declaration.
In C the creation of variables musst be the first declaration of a block.

Re: Unexpected declaration

PostPosted: Sun Mar 02, 2008 9:13 pm
by edh
Doh! :oops:

Thanks Makslane, I forget about that.

Re: Unexpected declaration

PostPosted: Thu Mar 06, 2008 5:54 am
by Fuzzy
I usually set my conditionals at the end of the block "canKick = 0;" so that its never activated until all my block has fired.

Which means I didnt know about that "gotcha". Its good to know! Thanks Makslane!

Re: Unexpected declaration

PostPosted: Thu Mar 13, 2008 4:52 pm
by edh
I tried setting this conditional early to avoid a race. Occasionally, I end up with more than one kicked ball on the screen. Still.

I'm going to have to rethink this... :?