Random Function Workaround, or Resolved?

butterbeanbutterbean Member Posts: 4,315
edited November -1 in Tech Support
I noticed people were having trouble with the "Random" function.

Is there a workaround to this? Or has this been resolved?

I'm trying to randomize the position of an actor after they perform a task

any help appreciated!

Comments

  • Rob2Rob2 Member Posts: 2,402
    I have found that random tends to work ok if it is in a change attribute behaviour...
  • butterbeanbutterbean Member Posts: 4,315
    Yeah trying to figure out the best plan of action

    I'm trying to randomize an enemy's position once they've fired at the player, but the random function doesn't seem to work

    I'm using "Interpolate" self.position X to random (340,750,890,1020) <---- These are random X coordinates. (timer over 1.5 seconds)

    It doesn't seem to randomize the position, but perhaps someone could shed light as to what I might be doing wrong?
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    Are you just trying to randomize the X, or both X and Y?

    If the latter:

    Interpolate self.position.x to random(0,480)

    Interpolate self.position.y to random(0,320)

    The random function only accepts 2 parameters, and it looks like you are feeding it 4 "random (340,750,890,1020)", which wouldn't work.
  • Rob2Rob2 Member Posts: 2,402
    Try assigning the random to an attribute and then interpolate to that
  • butterbeanbutterbean Member Posts: 4,315
    Thanks guys

    So should I assign the random to an integer attribute?

    What would be the best way to set that up? Sorry, I think I have an idea but just want to make sure
  • butterbeanbutterbean Member Posts: 4,315
    I figured it out, I did a change attribute, then assigned each position to the integer

    Thanks again!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    And you can only specify a range in the random function of two numbers.

    So random(0,480) will give you a random integer between 0 and 480.

    You cannot have:

    random(340,750,890,1020)

    If you want something like that, you need to set up Rules.

    Change Attribute: self.myRandomNumber To: random(1,4)

    Rule
    If self.myRandomNumber = 1
    -----Change Attribute: self.spawnPosition To 340
    otherwise
    -----Rule
    -----If self.myRandomNumber = 2
    ----------Change Attribute: self.spawnPosition To 750

    etc..
Sign In or Register to comment.