playMaker

Author Topic: [SOLVED] many properties/variables in many objects?  (Read 2750 times)

pustur

  • Guest
[SOLVED] many properties/variables in many objects?
« on: June 24, 2012, 03:02:25 PM »


I continued my minesweeper game in the last days but now i have a question.

i would like to know if there is an easy way to set many properties for each cube in the map.
in my case i have 30x16=480 cubes in my map and each of those will have the same properties but with different values.
for example:
-the number of surrounding mines
-has been "flagged" or not
-is a mine or not (at the moment i'm using a tag for this and it works well)
-etc.

thanks for reading!

EDIT: i found this video that talks about classes, may this be the answer?
« Last Edit: June 25, 2012, 09:06:42 AM by Alex Chouls »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: many properties/variables in many objects?
« Reply #1 on: June 25, 2012, 01:10:33 AM »
Hi,

 Yes "Class" is the concept that will help you achieve Object Oriented Design. In playmaker, a given FSM can be seen as a class.

I would recommend you study "prefab" if you have not yet used them in this game. Basically you will create a single cube "behavior" acting as a reference for the other. to create the board you will simply instantiate this prefab to form that grid, and likely store a reference of the gameObject or even better the main Fsm of that prefab in an array.

 Have you gone that far?

Your cube prefab will have several global events so that you can set and get its properties. for example:

"DEFINE AS MINE" would be the event you call on a cube so that it turn itself as a mine ( called during the init of the board

"COMPUTE SURROUNDING" would be a call to a cube so that it checks its surrounding cubes to find out the number of close mines.

"REVEAL" would be the event you call when the user click on it, and fire a series of logical step to.

"FLAG" would be the event when the user thinks that cube is a mine

Now to get information from a cube, for example when you check surrounding mines, you simply access variables you will have defined such as "IS MINE" "IS FLAGGED" "CLOSED MINES" etc and further walk your board to reveal an empty area for example.

Hope this helps,

 Jean

pustur

  • Guest
Re: many properties/variables in many objects?
« Reply #2 on: June 25, 2012, 06:16:53 AM »
yes i have a prefab with the FSM component attached to it.
my first idea was this:
i make a variable "clicks" which is going to increase after each click on a cube.
i click 4 times the cube number 1 ---> the variable should be 4.
then i click 3 times the cube number 2 ---> the variable should be 7.

but that's not true, the variable has a value of 4 in the cube number 1 and 3 in the cube number 2! so it's like having 2 different variables.

so, problem solved  ;D

thank you for the help and availability  ;)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: many properties/variables in many objects? [SOLVED]
« Reply #3 on: June 25, 2012, 07:10:10 AM »
anytime!