How to randomly change position using tables

ThemistoklesVThemistoklesV Member, PRO Posts: 138
edited March 2012 in Working with GS (Mac)
hello gurus,

im struggling with this issue:
i have a scene and outside the scene i have 1 actor 6 times so basically the same actor with 6 different pics which are my buttons.
i need to make them appear randomly on the scene at 6 specific positions when the game starts, so i created a table with 2 columns x,y(real attributes) and wrote the 6 different positions ex: x:80- y:100. Then at each actor i used the Interpolate behavior with:

self.Position.X --> tableCellValue( game.Tb Button Position ,1, game.spawn point ) 1 corresponds to x position of the table
self.Position.Y -->tableCellValue( game.Tb Button Position ,2, game.spawn point ) 2 corresponds to Y position of the table

My problem is now that the actors appear on the scene randomly but ALL in the SAME position.

Any suggestions in order to make them take different positions from the table?? I need to create another table with the ids of those positions??

Any help will be VERY appreciated!!!

Comments

  • simo103simo103 Member, PRO Posts: 1,331
    edited March 2012
    @ThemistoklesV ... I would create a self.WhatNumberamI (integer) attribute on the actor. Then click on each of the actors and then assign 1 to 6.

    I would create a Game attribute RandomRow and in your game have a Scene controller that sets Game.RandomRow to random(1,10) ...

    I would then create 2 tables one for X values one for Y. Each with 6 columns and 10 rows (10 more or less this is up to you).
    In each row enter your six X values (and Y in other table). Do the same for each row and mix them up so it could be Row1 400,390,32,86,222,316 Row2 180,310 .... etc

    then your X statement would be: self.Position.X --> tableCellValue( game.TableX ,self.WhatNumberamI, game.Game.RandomRow) do the same for Y

    I think that should give you great randomness without two of the same positions being chosen (which could happen if you were using random in other ways.

  • ThemistoklesVThemistoklesV Member, PRO Posts: 138
    @simo103

    thanks a lot i ll try your suggestion .... and i ll post the result

    thanks again!
  • ThemistoklesVThemistoklesV Member, PRO Posts: 138
    @simo103

    well, this suggustiond did the trick almost....

    the actor(1 but 6 times so 6 actors) did get different positin with tableX and tableY but many times the actor(1 but 6 times so 6 actors) may have the same position....

    how can i assure that the actor(1 but 6 times so 6 actors) dont have the same position ?

    thanks again ...
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2012
    The basic problem, if I understand it correctly, is a way to choose all six numbers from 1-6 (your actors) in random order without duplicates. I've tried to solve this issue in one of my games and the best solution I came up with was to pick a random number and add it to a text attribute (change attribute game.pickedNumbers to game.pickedNumbers..randomNumber). I added a timer and inside the timer I have a rule that says if the text attribute contains the randomly generated number, pick another random number. So in the log, I would see "picked 4, spawned 4; picked 3, spawned 3; picked 3, picked 1, spawned 1" etc. To implement this, I used a spawner actor that moves from position to position (your x and y values in your table) and picks a random number while in that position and spawns the corresponding actor at 0,0 relative to the spawner actor. Hope that makes sense!

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

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Yes it sound similar to how random card matching games are done.
  • ThemistoklesVThemistoklesV Member, PRO Posts: 138
    I would like to thank all of you for your help and your suggestions and mostly i would like to thank tshirbooth for his "boost" and his suggestions !!!
Sign In or Register to comment.