array/variable/destroy

Game Editor comments and discussion.

array/variable/destroy

Postby ckn087 » Tue Oct 25, 2016 2:01 am

I am working on a level in my game that has 2 enemy actors. (enemy2.0) and (enemy2.1) I made an array off the first one. I'm trying to get it to create a small timer when both actors are destroyed and then move view to next level. No matter what I try I can't get it to work. If I use destroy actor command, the view moves when just one is destroyed. How can I make it move after both are destroyed? I was thinking a variable but I can't get that to work either. I tried this: Create actor/Script Editor enemy_units = 2; Collide/Script Editor enemy_units --; and Draw Actor/Script Editor if(enemy_units ==0)
{
view.x=view.x =+320;

What am I doing wrong here?
ckn087
 
Posts: 30
Joined: Thu Jan 14, 2010 12:29 pm
Location: U.S.A
Score: 1 Give a positive score

Re: array/variable/destroy

Postby lcl » Tue Oct 25, 2016 6:08 am

Hi there! :)

Well, first of all, your code is broken. This is not correct:
Code: Select all
view.x = view.x =+320;

Here's the correct version:
Code: Select all
view.x = view.x + 320;

And another way of writing the exact same thing is this:
Code: Select all
view.x += 320; //note the order of the + and the =


What you have seems to be some sort of a hybrid of those two ways of incrementing a variable's value.

Let me demonstrate you how GE interprets those codes one by one. Let's start with your code, the one that is not working:

view.x = view.x =+ 320;

Here's what Game Editor makes of your code. (The code above is colored. In the description below the section that has the same color as the code explains what that part of the code means):

Set view actor's x to set view actor's x to positive 320.

Now that sentence above doesn't make any sense, right? You notice that your code repeats itself, saying the same thing twice at the beginning. And then it proceeds to set view's x to be 320. Yes, it sets view's x to 320, don't let the + mislead you. When you write your code like that, the + only means you want positive 320. It doesn't add 320 to anything.



Now then, let's take a look at how GE interprets the correct versions of the code:

view.x = view.x + 320;

And here's what Game Editor makes of that:

Set view actor's x to the value of view actor's x coordinate incremented by 320.

Now, that sentence makes more sense, doesn't it? :) As a result of this code the view is moved 320 pixels to positive direction on x axis.



The last version is pretty similar to the previous one, and it does the exact same job. The only difference is that the code is shorter, and thus, many people prefer to use this method, because of laziness :D

view.x += 320;

And here's what Game Editor makes of that:

Increment view actor's x by 320.

Or to put it another way for making it more obvious that this is just a more compact version of the previous one:

Set view actor's x to view actor's x incremented by 320.



Now then, let's move on to other things. Firstly, he code you posted has one more problem. It lacks the last } to end the scope after the if. But I guess it was accidentally left out from selection when you copied your code here?

Otherwise, with this information I don't see any reason why your code shouldn't work after fixing the first thing I mentioned about. One thing to check is that does the value of enemy_units ever reach 0? In what actors Create Actor event are you setting it to 2?
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: array/variable/destroy

Postby ckn087 » Fri Oct 28, 2016 4:02 am

Got the view to work thanks! But yes leaving that out was just a typo lol. I have create actor set on enemy 2.0. I'm not sure what I'm doing wrong.
ckn087
 
Posts: 30
Joined: Thu Jan 14, 2010 12:29 pm
Location: U.S.A
Score: 1 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron