Page 1 of 1

if problem

PostPosted: Sat Mar 18, 2006 5:02 pm
by regine
I have a problem with an if-code.

Im use:

if(player.x = 72);
{
ChangePath("Event Actor", "noName", BOTH_AXIS);
}

But if i starting the game so the actor player will be go to place x 72.

Can you help me?

PostPosted: Sat Mar 18, 2006 7:54 pm
by twobob
Use = to assign a value to a variable
Use == to compare values
In your case use the following:
if(player.x == 72);
{
ChangePath("Event Actor", "noName", BOTH_AXIS);
}

PostPosted: Sun Mar 19, 2006 12:15 am
by Fuzzy
= means make equal or assign. == means compare.

Its one of the most annoying things in programming, because even the masters mess up and do it, and its so innoculous that its hard to find.

The reason you can assign a value to a variable in C, inside an if statement, is because the creators of the language are sadists. Of course, if you ask me, I'll tell you its so you can baffle my mortal enemy, the if statement. Unfortunately, he gets you right back.

In reality(who lives there?) very odd and rare moments might require you to set values inside an if statement.

PostPosted: Sun Mar 19, 2006 10:12 am
by regine
I have maked with the strategy from twobob.

But:

Now, the Actor with the Script change the path if the the actor is on place x 72 or any other place.

PostPosted: Sat Mar 25, 2006 10:26 am
by regine
Can anyone help me?

PostPosted: Sat Mar 25, 2006 2:32 pm
by Fuzzy
Could you reword your new problem? It is a little unclear.

PostPosted: Sat Mar 25, 2006 4:06 pm
by regine
Now, the Actor have the script changes the path if the actor player is on place x 72 or not.

Better?

PostPosted: Sun Mar 26, 2006 1:48 am
by Fuzzy
First of all, you should not use ; after the if statement. I just tested it, and it works either way, but thats not proper usage, and may cause bugs.

Can you post the section of code that is giving your problems? Show us a few lines before the if too, if possible, as well as several lines after if. Thanks, I hope I can help you.

PostPosted: Sun Mar 26, 2006 9:07 am
by regine
Code:

if(player.x == 72);
{
ChangePath("Event Actor", "noName", BOTH_AXIS);
}


I need, if the player is on place x 72 the event actor changes the path. But he do changes the path if the player on place x 72 or on any other place.

What is false at the script?


Edit: Now, i have tested with no ; and now the event actor dont changes the path if the player is on place x 72 or not.

PostPosted: Sun Mar 26, 2006 4:29 pm
by Fuzzy
Ok. this is tricky, and i must say, you are very patient. To learn to program in another language must be very hard! I am pleased that you try so hard.

I am writing this for my own sake too, because it is a very odd problem, and I want to understand it too. I hope it helps you as well.

When you put a ; at the end of the if, you are saying to GE that IF is finished. the {} brackets are a way to group commmands together, and they tie those commands to the IF.

Since you used ; GE goes ahead and does what comes next, and basically ignores what happened in the IF. It does the next lines all the time.

So when you take the ; away, it seems to be more broken, but its not. Its getting closer to being fixed!

Because we know the If line is fixed, we have to guess two things. perhaps player is not really at 72, or perhaps there is a problem with changepath.

First we will test to see if we get to 72 for sure.

Make a testing actor, and make it a text actor. Make the text say "NOT 72!" to start.

then we change your code a little bit!

if(player.x == 72) // no ;!
{
// stop this action for now. ChangePath("Event Actor", "noName", BOTH_AXIS);
Testingactor.textNumber = 72;
}

Try that. If it works, then we know the problem is somewhere in the ChangePath("Event Actor", "noName", BOTH_AXIS);

If it works, you will see right away! This trick works in all sorts of places for testing problems.

I'll check back as soon as I can! I want to get you past this. If anyone else sees, and wants to help before I do, go ahead! Lets get regine past this!

You can put the ; back to see what it does to the code. // means comment, and causes GE to not use that line, if you did not know. Its great for leaving notes!

PostPosted: Wed Mar 29, 2006 3:04 pm
by regine
Now, i have found the problem with your help.

Thanks!