[SOLVED] Event: Keyboard + Instance Variable not working

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • ...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:

    [attachment=1:2rasnq1f][/attachment:2rasnq1f]

    Now if this were code I'd expect this to work:

    // 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)
    }
    [/code:2rasnq1f]
    ...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 :*
    
    [b]SOLUTION:[/b]
    
    

    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).

    [attachment=0:2rasnq1f][/attachment:2rasnq1f]

    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.

  • 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, .

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • [ 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.

  • 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).

  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)