Posted By
|
Message
|
Spiriax
Registered 25/05/2005
Points 277
|
3rd January, 2010 at 01:32:19 -
So, I have a grid-based Puzzle game going, where I thus far only have the main player and some movable blocks.
Whenever you press any of the arrow keys, the player will move to the next square in the grid (he slides forward, not teleports, but that's irrelevant).
Anyway, I have an Undo feature. An Undo feature which saves the player's position, and when you press Backslash he will move (this time like a teleport, making it look like a rewind like he slides back would be too hard for me, but that's ok!).
I have coded this for the player object:
Whenever the player moves, Global Value A gets plus 1. So if you moved 13 times, Global Value A is 13.
And whenever the player is standing still, the Data Store 2 object saves it's position. Like this:
Alterable Value A = 0
Alterable Value B = 0
Alterable Value C = 0
Alterable Value D = 0
* Data Store 2 object = Set Value Number Global Value A to X( "Active" )
* Data Store 2 object 2 = Set Value Number Global Value A to Y( "Active" )
(Alterable Value A is more than 0 if he's moving Left, Value B is if he's moving Top, etc, I think you get it..)
This is to save the position. Now, the Undo part:
Upon pressing "Backspace"
Alterable Value A = 0
Alterable Value B = 0
Alterable Value C = 0
Alterable Value D = 0
Global Value A > 0
* Subtract 1 from Global Value
* Active Object = Set X position to GetValue( "Data Store 2 object", Global Value A)
* Active Object = Set Y position to GetValue( "Data Store 2 object 2", Global Value A)
This works just swell.
But the PROBLEM is making it work for movable blocks! If I create another 2 Data Store objects, it can only save the position for one of the blocks (pretty logic though lol), so if I have let's say 8 blocks and I move them around, when I then press Backspace all blocks will jump to a saved position of one random block.
So how do I do? Do I have to create 2 Data Store objects for every movable block in the level, and then use the Spread Value function on the blocks so the Data Store objects randomly assigns a block to save it's position?
I might need like 40-50 Data Store objects, so that seems like sloppy coding.
I'm pretty bad with coding so please enlighten me.
Thanks.
n/a
|
CakeSpear
Registered 28/01/2004
Points 112
|
3rd January, 2010 at 02:01:51 -
Use an Array object to store the blocks positions in. Like this
1,1 BoxID(SpreadValue) 1,2 BoxXposition 1,3 BoxYposition
2,1 BoxID(SpreadValue) 2,2 BoxXposition 2,3 BoxYposition etc...
You don't need more than 1 array object
n/a
|
Spiriax
Registered 25/05/2005
Points 277
|
3rd January, 2010 at 02:14:22 -
Thanks, I'll probably redo the whole thing. But I have never understand how the heck an Array works, I've been told to use the Array object years ago but I just don't understand it. Any array tutorial around?
n/a
|
Spiriax
Registered 25/05/2005
Points 277
|
3rd January, 2010 at 02:56:49 -
I can't get the freaking thing to work!!!
If my grid is 64x64, do I have to input 64x64 in it's settings? I also chose number array.
n/a
|
Rob Westbrook
Registered 25/05/2007
Points 193
|
3rd January, 2010 at 03:25:57 -
If the grid you're using is 64x64 then a number array will need to be 64x64 as well, although bear in mind for calculations, unless you set it to be a base-1 index, the first column of cells will be 0, and the last 63.
There are 10 types of people in the world: Those who understand binary and those who don't.
|
Spiriax
Registered 25/05/2005
Points 277
|
3rd January, 2010 at 03:44:49 -
Ty Rob!
I hate arrays. I'm so confused.
I have now got it to work with the main player, but not the blocks. I coded it like this:
To save position:
Alterable Value A = 0
Alterable Value B = 0
Alterable Value C = 0
Alterable Value D = 0
* Array = Write Value X( "Active" ) to (1, 1, Global Value A)
* Array = Write Value Y( "Active" ) to (1, 2, Global Value A)
I had to use a XYZ board I suppose?
And to load:
Upon pressing "Backspace"
Alterable Value A = 0
Alterable Value B = 0
Alterable Value C = 0
Alterable Value D = 0
Global Value A > 0
* Subtract 1 from Global Value
* Active Object = Set X position to ValueAtXYZ( "Array", 1, 1, Global Value A)
* Active Object = Set Y position to ValueAtXYZ( "Array", 1, 2, Global Value A)
This actually works, at the beginning when Global Value A went 0 the player went to the upper corner of the screen, I was like wut O.o. But I realized it had to do with Base 1 Index being checked, so I removed it.
But it's impossible to get this to work with the blocks. How shall I make the array read the blocks' spread values?
Edited by Spiriax
n/a
|
Spiriax
Registered 25/05/2005
Points 277
|
3rd January, 2010 at 05:09:17 -
LOL YES I GOT IT TO WORK!!!
I just did:
Start of Frame
* Spread Value 0 in ID
Then I needed one event for every block to be saved:
ID = 0
* Write Value X( "Block" ) to (3, ID( "Block" ), Global Value A)
* Write Value Y( "Block" ) to (4, ID( "Block" ), Global Value A)
ID = 1
* Write Value X( "Block" ) to (3, ID( "Block" ), Global Value A)
* Write Value Y( "Block" ) to (4, ID( "Block" ), Global Value A)
ID = 2
* Write Value X( "Block" ) to (3, ID( "Block" ), Global Value A)
* Write Value Y( "Block" ) to (4, ID( "Block" ), Global Value A)
..for every block in the level.
And then in this event:
Upon pressing "Backspace"
Alterable Value A = 0
Alterable Value B = 0
Alterable Value C = 0
Alterable Value D = 0
Global Value A > 0
* Subtract 1 from Global Value
* Active Object = Set X position to ValueAtXYZ( "Array", 1, 1, Global Value A)
* Active Object = Set Y position to ValueAtXYZ( "Array", 1, 2, Global Value A)
I added:
* Block = Set X position to ValueAtXYZ( "Array", 3, ID( "Block" ), Global Value A)
* Block = Set Y position to ValueAtXYZ( "Array", 4, ID( "Block" ), Global Value A)
Thanks guys. I'm finally starting to learn arrays. But what value should I put in the array dimensions? Even if I put 1, 1, 1 it makes no difference. I just don't get it..
Edited by Spiriax
n/a
|
CakeSpear
Registered 28/01/2004
Points 112
|
3rd January, 2010 at 07:24:16 -
Think of arrays as a wall full of drawers. You can store data inside each drawer, but the drawers wont do anything themselves. You have to use the data stored inside the drawers.
Edited by CakeSpear
n/a
|
Spiriax
Registered 25/05/2005
Points 277
|
3rd January, 2010 at 14:58:04 -
Okay, thanks. I think I'm getting the hang of it!
n/a
|
[DELETED] Likes to put dots on paper
Registered 08/12/2008
Points 118
|
5th January, 2010 at 15:28:54 -
Arrays are so useful, when you get to using them often you will start to think of everything you are programming with data in a way that you can implement the array object.
n/a
|
|
|