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

Get help using Construct 2

Post » Sat Jun 21, 2014 6:59 am

I believe it's a precision thing. The chance for the enemy's sprite X position to be actually EQUAL to the image point X just when you're checking is pretty slim. You should work with approximate ranges, like so:

enemy_bbox X < Player_Target.ImagePointX(1) - 2
enemy_bbox X > Player_Target.ImagePoint(1) + 2

This checks if the enemy is within a 2 pixel distance from the point. The thing is, you cannot have both AND and OR conditions within the same event, so you will have to use another subevent to check for image point #2, and then either repeat the same actions in both subevents, use a 'isCloseEnough' variable and set it to 1 when the enemy is inside either of the ranges, then do the actions in a subevent with the condition isCloseEnough = 1, or (which I think is the better solution) create a function which takes two X values and a range, returns 1 if they are within the range, or 0 if they are not, and then use System Compare two values like so

System Function.Call("IsWithinRange", enemy_bbox.X, Player_Target.ImagePointX(1), 2) = 1
-or-
System Function.Call("IsWithinRange", enemy_bbox.X, Player_Target.ImagePointX(2), 2) = 1
B
6
S
2
Posts: 79
Reputation: 608

Post » Sat Jun 21, 2014 7:13 am

Thank you for looking at the code. The strange thing is that if I don't try to make states using variables and just put actions to be run when the enemy is in position, everything works (the enemy does attack when it gets in range). As soon as I set up the EnemyAction variables though, the actions that take place when the enemy gets into range do not work. I really don't think it has to do with precision only because it works otherwise, that's why I thought something was wrong with my code.

I do something similar to call on player attacks using variables to trigger animations to play, and they all work too. Just wish I could figure out what's wrong with this one event...

I guess I'll try adding an actual sprite for the enemy to try and overlap instead of imagepoints and see if that works. Thank you for the help so far!
B
4
Posts: 37
Reputation: 276

Post » Sat Jun 21, 2014 8:55 pm

Allowing the enemy to attack when it's stopped moving (so when it reaches the imagepoints) does work, but it's not what I need. I really do think I need states and variables because the enemy will do different things depending on what the player does, and it could get complicated.

...guh, my game is dead in the water if I can't find a solution that allows this (and I won't be able to justify buying the Personal version either). If anyone has any ideas that could help, even if it means completely redoing movement, I'm all ears.
B
4
Posts: 37
Reputation: 276

Post » Sat Jun 21, 2014 9:41 pm

I've only scanned the previous posts so sorry if this isn't what you are after, or has already been suggested but I've made a small example.

imagepointstate.capx


Again might not be what you are after but it's late and I'm not feeling 100%.
You do not have the required permissions to view the files attached to this post.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Sat Jun 21, 2014 10:58 pm

I appreciate it, thank you! Will take a look at it in a little bit and let you know. Hope you feel better soon!
B
4
Posts: 37
Reputation: 276

Post » Sun Jun 22, 2014 1:43 am

Also, thank you Trultz for the new information (sorry I couldn't reply via PM, I don't have enough rep yet). I'm rebuilding everything slowly now and I will try your and Minor's methods as soon as I'm able. Thank you very much!
B
4
Posts: 37
Reputation: 276

Post » Sun Jun 22, 2014 8:03 pm

I think I got it working by just having the enemy hitbox overlap an invisible player bounding box instead the two imagepoints. Probably was a combination of the overlapping imagepoints not working exactly as I thought (hope it's not a bug though) and the unusual movement system I'm trying to make. Thanks very much to everyone who suggested ideas!

I do have another slightly-related question if you don't mind (and I'd rather not create a whole new thread for in case it's a very simple fix). Now that the enemy does stop once within range and begin to attack (by calling a random animation), I can't figure out how to force an animation to play all the way through before calling upon another random value. They keep getting interrupted as the random command is called 60 times per second.

I tried Trigger Once While True and a few other methods I read in tutorials and none of them seem to work here. Like I said, I'm probably missing something very obvious, but I posted an example of the code with blank actions and was hoping someone could give me some advice. :) All of the movement that is now working is included in that example too. Hopefully it might help someone else avoid all the frustration I went through!

Sorry to ask again and thanks in advance for your help!

enemyattack.png
You do not have the required permissions to view the files attached to this post.
B
4
Posts: 37
Reputation: 276

Post » Sun Jun 22, 2014 9:02 pm

If your attack animations don't loop you can have this check along with your enemyattack = x conditions

enemy Animation Frame = enemy.AnimationFrameCount - 1

This checks if the sprite is in the last frame of its current animation. However, this may cause the animation to be cut a little short (because the check could come as soon as the last frame starts), so I recommend you pad all of your attack animations by repeating the last frame at the end
B
6
S
2
Posts: 79
Reputation: 608

Post » Sun Jun 22, 2014 9:45 pm

I'm sorry, but I don't understand how to write the code you recommended. For my example, would it be something like Add Condition -> Enemy Sprite -> Compare Frame -> Equal to -> "enemykick1" = enemy.5 -1 (I don't know how to write the last bit)?
B
4
Posts: 37
Reputation: 276

Post » Sun Jun 22, 2014 10:15 pm

Joy wrote:I'm sorry, but I don't understand how to write the code you recommended. For my example, would it be something like Add Condition -> Enemy Sprite -> Compare Frame -> Equal to -> "enemykick1" = enemy.5 -1 (I don't know how to write the last bit)?


Image

That's the condition. Replace Bullet with enemy of course. AnimationFrameCount is an expression that returns the amount of total frames in the current animation of the sprite.
B
6
S
2
Posts: 79
Reputation: 608

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: Kenthria and 13 guests