GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Or?

joelloydjoelloyd Posts: 119Member, PRO

When making a rule, what do i use to say or?

example, im placing it in the position of a spawned actor and iv got 3 attributes constantly changing at random. I want it to randomly choose one of the 3 attributes. so like,

random(attribute1 or attribute2 or attribute3)

something like that if possible, thanks

Comments

  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,913Member

    Can you expain why three attributes? You would need to add another layer of random code with three different rules looking at each of the three attributes. Not a very efficent method.

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

    @joelloyd said:
    When making a rule, what do i use to say or?

    . . . iv got 3 attributes constantly changing at random. I want [the rule] to randomly choose one of the 3 attributes.

    Like The_Gamesalad_Guru said, it's not clear why you'd need 3 random choices ?

    Why could you not simply have a single random number generator ?

  • tintrantintran Posts: 453Member
    edited July 2015

    you could try something an expression like this
    (random(1,3)==1) and attribute1 or
    (random(1,2)==1) and attribute2 or
    attribute3

    so it'll evaluate random(1,3) if you get a 1 it'll return attribute1. so 2/3 of the time it'll go on to evaluate the rest of the expression.
    next since there's 2/3 you want it to return attribute2 half of the time so that's why the random(1,2)==1 which occurs statistically 1/2 the time....
    and what's left is 1/3 of the time it'll just return attribute3.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,913Member
    edited July 2015

    @tintran said:
    you could try something an expression like this
    (random(1,3)==1) and attribute1 or
    (random(1,2)==1) and attribute2 or
    attribute3

    so it'll evaluate random(1,3) if you get a 1 it'll return attribute1. so 2/3 of the time it'll go on to evaluate the rest of the expression.
    next since there's 2/3 you want it to return attribute2 half of the time so that's why the random(1,2)==1 which occurs statistically 1/2 the time....
    and what's left is 1/3 of the time it'll just return attribute3.

    Yes but that just bloats the code needlessly as he obviously has a specific purpose for each of the three and you'd need rules for what each attribute does. If he tells me why, i can show him a way to do it in an intergrated way. He may need those three values for specfic reason but once I know their purpose i could build a better logic branch than that.

  • mhedgesmhedges Raised on VCS Posts: 634Member
    edited July 2015

    If I understood what you are trying to ask, you need to create a Rule which says:

    When Any conditions are valid:
    Attribute Game.RandomPosition = 1
    Attribute Game.RandomPosition = 2
    Attribute Game.RandomPosition = 3

    Then insert your behavior or attribute.

    Pure speculation on my part: I imagine that when GameSalad was made, they thought of a person with no programming skills whatsoever, or of using colloquial English. The Rule behavior is really an "if-then" statement, where "all" is "and", and "any" is "or".

    Edit: You need to have a Change Attribute behavior which would say:

    Change Attribute Game.RandomPosition to random(1,3)

    somewhere before the Rule.

  • tintrantintran Posts: 453Member

    @The_Gamesalad_Guru said:
    Yes but that just bloats the code needlessly as he obviously has a specific purpose for each of the three and you'd need rules for what each attribute does. If he tells me why, i can show him a way to do it in an intergrated way. He may need those three values for specfic reason but once I know their purpose i could build a better logic branch than that.

    True, true!

  • joelloydjoelloyd Posts: 119Member, PRO

    At the pace my actors are being spawned, the random generator doesn't look random at all. With a doodle jump type game the platforms as in going up are half the time going left to right in a line and not randomly placed. That's why. I was going to have 3 attributes constantly changing the spawn position on the X and choose one of 3 to see if it made it any better

  • KevinCrossKevinCross London, UKPosts: 1,893Member
    edited July 2015

    You could put your 3 random X positions in a table and then randomly pick one of the 3 rows i.e.:

    self.Position.X = tableCellValue(table name, random(1,3), 1)

    I may have got the rows and columns the wrong way around in that example.

    And if you want those 3 values to change throughout the game you would just update the table cells with the new values.

    If you don't want to use tables then have 3 rules and an attribute to store the random number i.e.:

    Change Attribute: self.randomNo = random(1, 3)
    Rule: If self.randomNo = 1
    ..Change Attribute: self.Position.X = game.attribute1
    Rule: If self.randomNo = 2
    ..Change Attribute: self.Position.X = game.attribute2
    Rule: If self.randomNo = 3
    ..Change Attribute: self.Position.X = game.attribute3

  • joelloydjoelloyd Posts: 119Member, PRO

    thanks for the help, worked out well like this, seems a bit more random

Sign In or Register to comment.