Change attribute x and y until both different from 0 not working
stefdelec
Member, PRO Posts: 146
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
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
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.
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
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?
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)]
?
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)
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
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 !
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.
Didn't I solve this for you before? What's changed in your requirements? Or was that someone else?
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
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.
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
Not sure what that means ?
I'm also not sure what that means either, but as @tatiang say you cannot constrain an attribute to (-1;1).
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.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
@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. "
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.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
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!