[SOLVED] Event: Keyboard + Instance Variable not working

Get help using Construct 2

Post » Tue Sep 23, 2014 2:13 pm

...solution is at bottom of post...
G'day guys. (my very first question)

I'm sure this is just a noob issue. I've looked in "[How do I]Frequently asked questions" but don't see anything that appears to have my resolution.
I have had some issues understanding the 'tree' in the Events page. I did google for that too but didn't get the explination I was looking for.

I managed to work out plenty of other stuff from google and looking at some example projects. I'm sure this will make perfect sense to me too once it's pointed out.

Trying to: Trigger actions based on two conditions. (keyboard) + an instance variable. (checked in properties and in debug mode the variable is correct)

Screen shot:
scirra001.png




Now if this were code I'd expect this to work:
Code: Select all
// Yes I just made things up but i'm sure you'll get the idea.
if ((keyboard.keypressed == space_key) AND (Player.CanShoot == "YES")){
   Player.State = "Shoot";
   spawn (ShootBullet);
   ShootBullet.angle = 270;
   // (and so on)
}

...or to just put one IF inside the other.

So what am I Noobing up?

last note: I intentionally used a text variable instead of a boolean.

Thanks in advance :*

SOLUTION:
blackhornet wrote:C2 is a bit inconsistent on this: it's because you put quotes around YES in your default CanShoot instance variable (although you didn't for the State=Normal case).

c2properties.png

Removing the quotes from the instance variable of the object resolved the issue.
Keep the quotes in the conditions of the events sheet

#2 in the first image posted now functions.
You do not have the required permissions to view the files attached to this post.
Last edited by humpty on Tue Sep 23, 2014 11:44 pm, edited 3 times in total.
B
7
S
1
Posts: 26
Reputation: 549

Post » Tue Sep 23, 2014 2:38 pm

Text variable contents are case sensitive, is the player CanShoot instance variable definitely "YES" by default on the Player object? Also, for future, if you could attach a .capx people can debug it easier as it's possible other settings are affecting it, :).
Founder of Jadelight Studio, Developer of Libertas Aedifex, regular C2 Help contributor and fan of ambient music and Star Wars.
B
12
S
4
Posts: 255
Reputation: 2,008

Post » Tue Sep 23, 2014 10:58 pm

[ CAPX attached ]

G'day inquiesco,

Thanks for the reply and help.

I truly believed it was me incorrectly using the event sheet so didn't think the capx would have helped. Sorry, it's attached now.

Variable Case Sensitive: Yes, the text variable is upper case through the entire project.

Further testing: I have done some more testing and believe that the issue is entirely checking the variable. I just can't see where / how / why its an issue ;)

I have commented the code in the capx with all comments ABOVE the section they apply to and also used groups and a "START / END" comment to isolate where the issue is ocuring.

I am now also lead to believe that I have used the event structure correctly and that the issue has nothing to do with the structure for the desired outcome but has everything to do with the wrong condition-checking or an issue I generated in my Instance Variables. ......is that correct?

Thanks again in advance.
You do not have the required permissions to view the files attached to this post.
B
7
S
1
Posts: 26
Reputation: 549

Post » Tue Sep 23, 2014 11:22 pm

C2 is a bit inconsistent on this: it's because you put quotes around YES in your default CanShoot instance variable (although you didn't for the State=Normal case).
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Tue Sep 23, 2014 11:29 pm

OMG!
Thanks heaps for that blackhornet. Where do I send the 40 foot yacht as a gift of my appreciation?

I knew it would be simple and doubt I'll have this issue again now :) :) :) :)

I can't see a method to flag your post specificly as the solution or to give you a 'thumbs up' or 'reputation booster' or similar.
THANK YOU
B
7
S
1
Posts: 26
Reputation: 549


Return to How do I....?

Who is online

Users browsing this forum: jbr190 and 41 guests