How do I perform comparisons inside a function?

0 favourites
  • 5 posts
From the Asset Store
94 Inside buildings views - Isometric view - PNG transparent - 2048x2048
  • I'm new to the event system of Construct 3 and this makes me feel like a total noob as I know this would take less than a second in a "traditional" language / system.

    I'm making a game where a monster tracks the current mouse position and "shoots" out his tongue when the user clicks the left button (by increasing the size of the sprite) .

    I'm using an instance variable inside the tongue object to hold it's current state (static, shooting forward or pulling back) and I've created two functions - one that's called when the user clicks the mouse to start the animation and one that's called every tick to update the current tongue size based on it's state.

    This is the thing - I can't for the life of me work out how to put an if statement (or a basic comparison) into the action associated with the function - I want something like this...

    	function UpdatedTongue() {
    		if (tongueState > 0) { 
    			// increase size up to max - then set state to -1
    		} else if (tongueState < 0) {
    			// decrease size down to zero - then set state to 0
    		}
    	}
    

    Any help is greatly appreciated.

    8-)

  • + Tongue: TongueState > 0

    -> (no actions)

    + System: Else

    -> (no actions)

    Manual article on Instance variables

    Else is a System condition

  • Hi Kyatric,

    Thanks for the quick reply, I can sort of see how that works if I add the compare as an event, but I'd like to add it as an (conditional) action within a function.

    I think I'm missing something fundamental here - under what circumstances would the construct runtime execute the code as this is a comparison not an event.

    Would the runtime run this code every frame as long as the condition is true - because I'd have expected that to have been handled by the system "every tick" event, or is an event generated whenever the value of tongueState changes and satisfies the condition.

    Thanks in advance for the help and sorry for the noob questions :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think what you’re missing is sub-events. You can drag an event under and to the right of another event to make it a sub-event. Kind of like indention formatting of some programming languages.

    Hope that helps.

  • Bingo, I think that’s exactly it.

    Thanks for pointing it out to me 👍

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