How do I set states with variables? Not sure what's wrong

Get help using Construct 2

Post » Sat Jun 21, 2014 5:11 am

I worked on this all day and I absolutely cannot figure out what is wrong. Probably something really simple, but I'm just not seeing it.


I have an enemy that checks to see if it's touching one of two imagepoints on a player object =

Enemybbox (inverted) X = Player_Target.ImagePointX(1) | Player_Target.ImagePointX(2)

If it does not (meaning the above script is true), a instance variable on Enemybbox called "EnemyAction" is set to a text value of "CHASE". This causes the enemy to move towards either of the Player's two imagepoints. That all works fine.


However, when the enemy reaches one of the player's imagepoints, I want to switch the instance variable from "CHASE" to "FIGHT", stop moving, and start following a new set of commands listed under an Enemybbox EnemyAction="FIGHT" action. The enemy does stop (because it reaches the imagepoint), but I can't get the variable to change. Even when it's stopped and when I have actions that tell the variable to switch to "FIGHT" once it's reached the imagepoint, in the debugger, it still shows the EnemyAction value as "CHASE".

Inverting the above script does not work (example below), and I've also tried this with global variables and it didn't work either.
Enemybbox X = Player_Target.ImagePointX(1) | Player_Target.ImagePointX(2) Set EnemyAction to "FIGHT"



I really want to use variables because I need to have different states for the enemy (chase, fight, hit, dead, evade, etc). Any help would be greatly appreciated!
B
4
Posts: 37
Reputation: 276

Post » Sat Jun 21, 2014 5:26 am

Make sure in your 'default value' for any Text variable, you aren't using quotes... Something along those lines anyway. Generally some places you need quotes, others you don't. Check them all.

Edit: I changed from using Text to Number in one place for this reason. I recommend using Number, and have constant variables to denote different 'states' or whatever, like MONSTER_ATTACKING = 1, MONSTER_DEFENDING = 2, etc.
Last edited by codah on Sat Jun 21, 2014 5:33 am, edited 1 time in total.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sat Jun 21, 2014 5:31 am

Thanks, but they all seem to be correct. No quotes in the default EnemyAction variable and all of the ones that are called upon have the quotes (or I get the error message saying it's an unknown expression).

(oh you edited your post, thanks). I did try that once, but I'll do it again and post again shortly.
B
4
Posts: 37
Reputation: 276

Post » Sat Jun 21, 2014 5:33 am

No worries.. even after I corrected mine I still seemed to be having issues. Switched to numeric variables and been fine since. I think they are less error prone because you can't misspell a constant variable's name :)

Edit: Yes if you don't use quotes where you need them, it will tell you. But if you use them where you don't have to, it won't. But if yours are fine, then I'm not sure. You could post a capx
Last edited by codah on Sat Jun 21, 2014 5:35 am, edited 1 time in total.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sat Jun 21, 2014 5:41 am

I changed the variables to numeric and I have the same results. I think the problem occurs when the enemy reaches one of the two Player's imagepoints (Player_Target.ImagePointX(1) | Player_Target.ImagePointX(2).)

Could you tell me how you might add an action to determine when the enemy has reached an imagepoint and switch the instance variable from 0 to 1 (or whatever)? Whatever I'm doing, it's not right. Very sorry I can't post a capx now, I'm making this for a friend and I'm not supposed to share it yet. If we can't figure it out though, I'll try to make a dummy one and at least post screenshots of the code.
B
4
Posts: 37
Reputation: 276

Post » Sat Jun 21, 2014 5:46 am

I think your

"Enemybbox (inverted) X = Player_Target.ImagePointX(1) | Player_Target.ImagePointX(2)"

condition is written the wrong way

What you want to do is

Enemybbox (inverted) X = Player_Target.ImagePointX(1)
Enemybbox (inverted) X = Player_Target.ImagePointX(2)

And if you want to invert the whole condition (to check if they are actually touching) you should do

Enemybbox X = Player_Target.ImagePointX(1)
-or-
Enemybbox X = Player_Target.ImagePointX(2)
B
6
S
2
Posts: 79
Reputation: 608

Post » Sat Jun 21, 2014 5:53 am

Also the chances that that values match exactly are slim. The usual technique is to use collision or overlap checks, possibly with hidden objects, positioned to the image-points.
ImageImageImage
B
71
S
22
G
248
Posts: 3,759
Reputation: 138,069

Post » Sat Jun 21, 2014 5:56 am

blackhornet wrote:Also the chances that that values match exactly are slim. The usual technique is to use collision or overlap checks, possibly with hidden objects, positioned to the image-points.


That's normally true, but we don't know exactly how he's handling his movement, so maybe it's just that precise.

In any case, @blackhornet is right, you shouldn't trouble yourself with manual collision detecting, since the engine does that quite well by itself
B
6
S
2
Posts: 79
Reputation: 608

Post » Sat Jun 21, 2014 6:16 am

Thank you for your help so far, I will try what you suggested and post again in a little while.


My sprites are attached to invisible primitive shapes that act as bounding boxes, and in this particular case, the enemy sprite moves towards the player until it's bounding box overlaps one of the two imagepoints on either side of the player. It actually works very well, there's just a tiny animation issue that I'll try to fix later. Got to fix this problem first. ;)
B
4
Posts: 37
Reputation: 276

Post » Sat Jun 21, 2014 6:42 am

Your commands do work (thank you), but the problem still isn't fixed. I'm sure I'm just missing something simple here, so here's an example of the code. Sorry to bother you guys with this!
You do not have the required permissions to view the files attached to this post.
B
4
Posts: 37
Reputation: 276

Next

Return to How do I....?

Who is online

Users browsing this forum: Jasmaniac, PRIZZRAK, Yahoo [Bot] and 16 guests