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

Game Editor comments and discussion.

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

Postby berighteous » Tue Jul 10, 2007 10:20 am

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.
berighteous
 
Posts: 52
Joined: Mon Apr 16, 2007 11:12 pm
Score: 1 Give a positive score

Postby metal_pt » Tue Jul 10, 2007 10:44 am

Hi!
You must use "=="

Code: Select all
if (ship_visible==1)
{
CreateActor("boom", "boom", "(none)", "(none)", 0, 0, false);
}
]v[eta[_ - Using GE since June, 15 2007
Currently using v1.3.8 Registered
metal_pt
 
Posts: 117
Joined: Sat Jun 16, 2007 12:57 pm
Location: Sintra, Portugal
Score: 2 Give a positive score

Postby berighteous » Tue Jul 10, 2007 5:02 pm

thanks. I knew it was something simple.

You'd think = would be enough. I guess in C 1=1 is a vague statement?
:lol:
berighteous
 
Posts: 52
Joined: Mon Apr 16, 2007 11:12 pm
Score: 1 Give a positive score

Postby Jay S. » Tue Jul 10, 2007 7:15 pm

"=" 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. :)
User avatar
Jay S.
 
Posts: 118
Joined: Thu Apr 26, 2007 6:51 pm
Location: My computer desk. :P
Score: 9 Give a positive score

Postby berighteous » Tue Jul 10, 2007 9:21 pm

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.
berighteous
 
Posts: 52
Joined: Mon Apr 16, 2007 11:12 pm
Score: 1 Give a positive score

Postby Jay S. » Tue Jul 10, 2007 10:09 pm

I'm glad it helped you!!! :D
User avatar
Jay S.
 
Posts: 118
Joined: Thu Apr 26, 2007 6:51 pm
Location: My computer desk. :P
Score: 9 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron