Change attribute x and y until both different from 0 not working

stefdelecstefdelec Member, PRO Posts: 146
edited September 2015 in Working with GS (Mac)

Hi,

I am trying to get attribute x and y both different from 0, and certain value depending on their location.

I created I small template => a template worth a thousands word.

Sometime I got 0;0. May you help me to understand ...and perhaps fix the issue?

Regards,

Stéphane.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited September 2015

    All of your random() expressions include zero as a possible value. If you don't want zero then don't include it in the expression. For example, random(-1,1) results in a value from {-1, 0, 1}. Instead, use 1-random(0,1)*2 which results in a value from {-1,1}.

    Where you have random(0,1), what are you wanting the outcome to be? Just 1? Or other possible values?

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

  • stefdelecstefdelec Member, PRO Posts: 146

    X can be 0 if, Y is not 0.

    So random(0,1) can be 0 or 1, if X or Y at least is not 0.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    I would recommend this approach: make a table with possible values, for example:

    -1
    0
    1

    Then, each time you need a pair of values that are not the same:

    choose a random row using Change Attribute game.row to random(1,tableRowCount(tableName))
    Change Attribute game.firstValue to tableCellValue(tableName,game.row,1)
    Delete Row at index game.row
    Change Attribute game.row to random(1,tableRowCount(tableName))
    Change Attribute game.secondValue to tableCellValue(tableName,game.row,1)

    You would then need to reset the table to its original state. This is usually done by Copying the Table to a backup table and using that for the above rules. Then when done, you copy the master table to the backup table again.

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

  • stefdelecstefdelec Member, PRO Posts: 146

    Hum... Ok. I ll try.

    But shouldn't the rule be working the way I wrote it?

    If x= 0 and Y=0 => constrain x(random) and constrain y(random). Isn't the syntax right?

  • SocksSocks London, UK.Member Posts: 12,822

    @stefdelec said:
    If x= 0 and Y=0 => constrain x(random) and constrain y(random). Isn't the syntax right?

    That doesn't seem to make any sense . . .

    [If X is equal to zero] and [Y is equal to zero] is equal to or larger than [constrain x ( random)] and [constrain x ( random)]

    ?

  • stefdelecstefdelec Member, PRO Posts: 146
    edited September 2015

    sorry... That was and arrow. I just wrote what is in the example I shared.

    If x= 0 and Y=0
    trigger:
    constrain attribute x to random(-1;1)
    constrain y to random(-1;1)

  • stefdelecstefdelec Member, PRO Posts: 146

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited September 2015

    I don't know how you can constrain an attribute to one of two values. In fact, you can't. Constrain means "keep an attribute at a constant value."

    Try my table method... it works. ;)

    The problem with your idea is that a rule will only trigger when its condition changes from false to true. So if x and y are both 0, the rule will then pick two more random numbers (assuming you're using Change Attribute instead of Constrain Attribute)... but if both are 0 again, the rule will NOT trigger because it was true and then stayed true. It would have to be false again before it would trigger when x and y both equal 0. Confusing, I know!

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

  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2015

    @stefdelec said:
    sorry... That was and arrow.

    Lol, I see, probably not a good idea to use mathematical symbols that are used in GameSalad as decorative / symbolic elements in descriptions of equations / rules ! :smile:

    @stefdelec said:
    If x= 0 and Y=0
    trigger:
    constrain attribute x to (-1;1)
    constrain y to (-1;1)

    Constrain means - on every draw cycle change this attribute to A.

    In your example A is (-1;1), what does it mean to change something to (-1;1) ?

    EDIT - what @tatiang said.

  • ArmellineArmelline Member, PRO Posts: 5,368
    edited September 2015

    Didn't I solve this for you before? What's changed in your requirements? Or was that someone else?

  • stefdelecstefdelec Member, PRO Posts: 146
    edited September 2015

    That was me. It changed, that I don't need as many and you suggestion was not really random. But thank you for you suggestion.

  • stefdelecstefdelec Member, PRO Posts: 146

    Every actor has an attribute which is saved in a table according to its position.

    So I use it, in order to check one of the actor around. (-1;1) means = case on the left and. upper

  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2015

    @stefdelec said:
    Every actor has an attribute which is saved in a table according to its position.

    Not sure what that means ?

    @stefdelec said:
    So I use it, in order to check one of the actor around. (-1;1) means = case on the left and. upper

    I'm also not sure what that means either, but as @tatiang say you cannot constrain an attribute to (-1;1).

  • ArmellineArmelline Member, PRO Posts: 5,368

    @stefdelec said:
    That was me. It changed, that I don't need as many and you suggestion was not really random. But thank you for you suggestion.

    My suggestion was random within the extremely restrictive conditions you requested. This looks like different and even more restrictive conditions.

    Perhaps if you explain what you're trying to achieve it might help people better understand how to get you to the point you want. I put a lot of time into the last solution and it 100% met your requirements, but since those have changed I'm reluctant to do that again unless I'm sure you're actually asking for what you want.

  • stefdelecstefdelec Member, PRO Posts: 146
    edited September 2015

    @Armelline No worries. I understand. I ll see if I can sort it out by my self.
    Thank you.
    @tatiang You answered my problem => "but if both are 0 again, the rule will NOT trigger because it was true and then stayed true. It would have to be false again before it would trigger when x and y both equal 0. "

  • ArmellineArmelline Member, PRO Posts: 5,368

    @stefdelec said:
    Armelline No worries. I understand. I ll see if I can sort it out by my self.

    That's not what I meant at all - what I was trying to say is right now we're looking at squares and numbers and no context. Put this into a context for people and you'll be more likely to get help.

  • stefdelecstefdelec Member, PRO Posts: 146

    I know what you meant. And I meant: with all the comments I had, I try by myself. If I cannot, I ll come back to the forum!

Sign In or Register to comment.