Page 1 of 1

my if's don't work. Can someone tell me what I'm doing wrong

PostPosted: Tue Jul 10, 2007 10:20 am
by berighteous
Can someone please gently tell me what I'm doing wrong, because I'm going batty because I can't get my if's to work in the script editor. I don't come from a C background, I'm used to things like if ship_dir=1 then do something, else do something else.

Here's what I want to happen: After my ship gets destroyed by an asteroid, I need to fly it back unto the screen, safe from harm for a couple seconds.

Here's what I'm doing:
I have a global variable called ship_visible. On the ship's create actor event I set ship_visible=1. When it gets destroyed, I create an explosion actor which plays the kaboom, and in a script I set ship_visible=0. Then for my asteroids, I have a script for the collion with the ship:
if (ship_visible=1)
{
CreateActor("boom", "boom", "(none)", "(none)", 0, 0, false);
}

thinking that if the ship hasn't been destroyed, destroy it, but don't if it has been. But it doesn't work. Now my ship is never destroyed, even though I set ship_visible=1 on creation of the ship. I looked up tutorials on C. This looks like the right construct. What am I doing wrong??? The variable is never changed, except by the explosion actor, which now isn't created. I'm confused.

without the If the ship gets blown up correctly, but when it comes back it too often gets nailed by another asteroid before it gets fully back on screen. I need to have it invulnerable for awhile.

I can't get any if something=somenumber to work. I can say if something>somenumber-1 and that works, but not if something=some number. I don't get it.

PostPosted: Tue Jul 10, 2007 10:44 am
by metal_pt
Hi!
You must use "=="

Code: Select all
if (ship_visible==1)
{
CreateActor("boom", "boom", "(none)", "(none)", 0, 0, false);
}

PostPosted: Tue Jul 10, 2007 5:02 pm
by berighteous
thanks. I knew it was something simple.

You'd think = would be enough. I guess in C 1=1 is a vague statement?
:lol:

PostPosted: Tue Jul 10, 2007 7:15 pm
by Jay S.
"=" applys a value to a variable. "==" compares a value of a variable.

I hope I worded that correctly so you could understand... it's pretty simple when you start using it a lot. :)

PostPosted: Tue Jul 10, 2007 9:21 pm
by berighteous
The description makes total sense. Thanx! My code works now. :D

When I went to college, pascal was the next hot thing. Not too many people knew C. I programmed in a compiled basic or Forth for what I needed. My first job in college was translating APL code from the mainframes to applesoft basic for the computer labs. I wrote all my games in Euphoria. It knows what = means! :lol:

The game is really taking shape now. I posted a new demo in the dev section.

PostPosted: Tue Jul 10, 2007 10:09 pm
by Jay S.
I'm glad it helped you!!! :D