Attribute range expression

LokitoesLokitoes Member, PRO Posts: 187

Hi guys,

I am working with accelerometer and want something to happen when it is within particular ranges.

For the expression, I want to say things like "when accel x is between +7 and +9, do this". Currently I just have this written in the expression window but I have no idea if this is ok or not?

And what if the range is between +3 and -3, or -3 and -5, not just plus values? Then the kind of simple expression that I have here wouldn't seem to apply anymore - how would I write it then?

Thanks all!

Comments

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,201

    you can add multiple conditions. do two with < and >

  • LokitoesLokitoes Member, PRO Posts: 187
    This is an embed external element. It can be deleted using the delete key or the backspace key. To view the full element, press the preview button below.

    Thanks adent42! Sorry to be a pain, but is this, below, what you mean? (I would just test it but when accel I have to export it every time to test it so it's slow going). Would that put it between 7 and 9?:

    Or can I do this to also include those numbers?:


  • LokitoesLokitoes Member, PRO Posts: 187
    edited September 2020

    @adent42 Sorry I just realised how dumb I am and that the symbols are already in there. Another quick question: can the accel attribute do decimal points?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    This is an embed external element. It can be deleted using the delete key or the backspace key. To view the full element, press the preview button below.

    Yes. I recommend adding some Display Text behaviors with accelerometer values and then testing on a mobile device so you can see what types of values you get.

    Also, @jamie_c has some terrific tutorials, accelerometer included: https://www.youtube.com/watch?v=JzluQc2XIiA

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • LokitoesLokitoes Member, PRO Posts: 187
    This is an embed external element. It can be deleted using the delete key or the backspace key. To view the full element, press the preview button below.

    Thanks tatiang! You know, I was using a separate app to check the accel parameters (one of those apps that shows you the different physics tools of your phone etc) and thought I had it all sussed and didn't need the display text for the values. But when I put in the display text, I realised it was a completely different decimal point range to what the other app was displaying. I guess that is a lesson learnt for the future. :)

  • LokitoesLokitoes Member, PRO Posts: 187

    Actually I said that so confidently and just made a spawnable actor that should technically be 'impossible' to spawn because the phone has to go outside the normal accelerometer value range in order to spawn, and after a few tries it somehow spawned... So maybe I still don't quite understand the values 😅oh well it's trial and error!

Sign In or Register to comment.