Quick Tip: Define game.ZERO = 0

ORBZORBZ Member Posts: 1,304
Because rules require the left hand value to be a variable here is a handy little thing you can do to make rules more flexible:

Create a game variable called ZERO with a value of 0

Now you can create rules that look like this:

Rule: game.zero < x - y

This is handy in certain situations... say for example you wanted to only do something if the speed of the object was less than 10.

Normally you'd have to constrain a variable Speed to magnitude(linearVelocityX, linearVelocityY) then create a rule that says if Speed < 10

With the game.ZERO value set you can skip the constraint and just write this:

Rule: game.ZERO < 10 - magnitude(self.linearVelocityX, self.linearVelocityY)


(Also, you may want to create a game variable called ONE with a value of 1 and a game variable called NegONE with a value of -1 for certain cases, but by far the most useful value is ZERO)

Comments

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    Nice tip - as always. :) Glad to have you back on the forums!
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
  • floydianspiralfloydianspiral Member, PRO Posts: 308
    I use this a lot for "every" timers, I think @HoneyTribeStudios originally taught me this...

    Rule:
    if game.ZERO = floor(self.Time)%someNumber
    [do something here]

    where someNumber is the amount of time you want something to happen (if you put 15 in there stuff would happen every 15 seconds). Careful as it would happen at the beginning of the scene as well. You can get around this by making your game.ZERO be something like game.TEN. I usually create the actual variable someNumber and put it in the expression because then you can change that and not have to go back into the expression editor again. Also self.Time could be game.Time or if you have already have a TIMER attribute which your game runs off of. Hope this helps someone else.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    very handy tip...

    especially useful if you want to check to see if a table value has been activated in a tidy way... which I've just done...


    e.g.

    if an item is unlocked, update a table (using Change Table Value) , then save the table.

    then you can use a rule somewhere:

    if: 'game.ZERO' < 'tableCellValue( table, row, column)' and touch is pressed

    open door...

    Thanks for sharing Orbs... I assume your stick rocking the world with your Maths know how some how...
  • ORBZORBZ Member Posts: 1,304
    @stormystudio

    Yup, you could use it for tables too. The reason I mention ZERO though specifically is that it's a special number. It's neither positive nor negative. It's unique along the numbers and also represents false in Boolean logic. So it's a rather useful constant to define since you can use it in a lot of places. 1 and -1 are similarly powerful and useful numbers. Pos and Neg Infinity are also helpful but beyond our needs most of the time since GS handles a lot of the heavy math for us.

    I've been around all this time off and on. I've just been working on my game in my spare time. Almost finished. I really hope you guys like it :) I would love to make games full time. I posted about it here:

    http://forums.gamesalad.com/discussion/56666/orbz-game-early-preview-feedback-plz#latest
Sign In or Register to comment.