Actor Identifier other than 'last created' and 'last collided'?

faile486

  • Posts: 15
I'm making a sudoku game, and each cell on the grid is a unique actor. There's a behavior attached that handles player input. I'm trying to create a 'check solution' button, and I need to be able to access the input attribute for each cell. I can't find a way to access anything but 'last created', 'last collided', and 'self'.


JeffreyDriver

  • Posts: 2262
Let's say that you use code attached to your scene to place the 'check solution' button, you can set that as a local actor attribute that you can then refer to easily later.

faile486

  • Posts: 15
Set what as a local actor attribute? Sorry, I'm not understanding ^^;

JeffreyDriver

  • Posts: 2262
See the example code I posted. Use code to create your 'check solution' actor on-screen, then under ATTRIBUTES, create an actor attribute called something like 'create solution button' and set it to 'last created actor'.

You can then refer to the 'create solution button' attribute as though it's an actor.

faile486

  • Posts: 15
But how does that get the input from the cell?

On scene creation, a list is created and propagated with the puzzle solution.
The player can then click an individual cell and input numbers.
When the 'solve' button is clicked, it gets the solution from the scene, but I don't know how to get the data that was typed by the player.

Are you saying that if the button is created from code, it would be the 'last created' actor, and then I could store the user input as an attribute on it?  So basically I'd have an attribute on the button for all 81 cells, and they would update each time the user data changes?

KramerGames

  • Posts: 405
You could add a number attribute to your cell actor called "ID" (e.g.). When the cells are created, set the ID for each actor, using the block "behaviors"-->attributes-->for last created actor set "ID" to x.

Next I would make a new list that stores all the players input, so make it a list that has as many items as your solutions list (I guess it's always 9 in Soduko :-) ), set each item to 0.

Now you need one more attribute to check which cell is activated, for simplicity I would just make a game attribute called "chosen cell".

Now you can add to your cell behavior:
when mouse is pressed
-if mouse is down on self
--set "chosen cell" to ID


Then when a key is pressed
replace item "chosen cell" in "player input list"

Now when checking for the solution all you have to do is compare the lists:

Set a boolean called "solution correct" to true
Set a number attribute "item" to 0
Repeat 9 times
-If NOT get item 'item' from list 'solution' = get 'item' from list 'player input list'
-set 'solution correct' to false
-increment 'item' by 1

After the loop you check if the 'solution correct' boolean is still true, if so, the game was solved.


Instead of the loop you could use the "each item in list" block, but I had some issues with that so I prefer to just make a loop.
Parasites United  (Idle Parasite Game)

KramerGames

  • Posts: 405


Are you saying that if the button is created from code, it would be the 'last created' actor, and then I could store the user input as an attribute on it?  So basically I'd have an attribute on the button for all 81 cells, and they would update each time the user data changes?


Yes, last created actor refers to that. Also I just realized sudoku has 81, not 9 cells lol.
Btw you could use a loop to create those cells and set those ID's, otherwise it will take ages to make all the blocks. Let us know if you need help with that.
Parasites United  (Idle Parasite Game)

faile486

  • Posts: 15
So I actually started making parts of the game before really understanding what I was doing...I made a grid in photoshop and sliced it into 81 cells in order to make all the line thicknesses work the way I wanted them to.  I didn't know that drawing an item via the engine was a thing.

The first iteration of the game did have all 81 individual actor types set up, but I lost it in a tragic data accident and the prospect of setting them all up a second time was just too much. Figured I'd get the basics out of the way before setting up the other 8 rows. Now I'm planning on going back and drawing them via the engine...very glad I didn't set them all up.

Think I've got what you're saying down, going to try it out. It still seems strange that I can't just say 'give me the value stored in the Input attribute of cell 53', though.

I've got you down in my 'special thanks to' document =)

faile486

  • Posts: 15
Drawing 81 cells using 'when drawing' is working fine, but I'm not sure how to turn them into actors. Creating 81 actors of the same time is causing Flash to freak out.

I had an almost identical block triggered by a 'when drawing' event, the only difference was it had 'set fill color' and 'fill rectangle' instead of 'create actor'.

Any ideas?

JeffreyDriver

  • Posts: 2262
If you're creating a sudoku game you probably don't need collision shapes on your actors, and you can use simple physics. Having 81+ static actors in your game shouldn't give you problems.

faile486

  • Posts: 15
Thanks! Went in and disabled physics. I didn't have to do that when I was placing the cells in the scene manually.

faile486

  • Posts: 15
In a sudoku puzzle, some of the numbers are given at the start. The cells containing these numbers need to be uneditable. I believe I can achieve this by making the 'player input' behavior inactive on these cells.

This will have to be done individually for each scene, so I think this should be an 'event' instead of a 'behavior', right? If I duplicate the scene and edit each scene's event, they would all be different?

cabinfever

  • Posts: 159
If you use actor attributes (for example: boolean editable) for those un-editable cells, then it is easy to check if this actors internal parameter allows editing or not.

You would set the value of this actor attribute when you create the actors. Then you do not need to maintain any arrays for this info.

faile486

  • Posts: 15
Is there a way to prevent a drawing event from triggering?  For instance, if I want to draw something only once, at scene creation, and never need it to update?

CmdrWhitey13

  • Posts: 505
Is there a way to prevent a drawing event from triggering?  For instance, if I want to draw something only once, at scene creation, and never need it to update?

Yes, it is possible. When created>boolean to true. When Drawing>draw once for boolean true. Then, set boolean to false.

Hope it helps.