Help with RPG rooms

For questions about using Classic.

Post » Thu Mar 04, 2010 2:25 am

Here is what I want to do:

1- The player breaks some "Bricks" in a room.
2- The player leaves the room/layout.
3- The player returns to the room/layout.
4- The rooms does not re-create the bricks the player destroyed, but remains as the player left it.

I tried doing this by creating a brick spawner that only creates one brick when it's private variable 'destroyed' equals 0.
So when I destroy a Brick, the brick get's destroyed but the brick spawner stays there, and I change it's private variable 'destroyed' to 1.

When I leave the room, I save each brick spawner UID as keys, and the value of their 'destroyed' variable as their corresponding value.
When I re-enter the room, I load the hash table, I compare the keys to find the corresponding instance with their matching UID (with the "brick spawner Pick by UID equals to Hashtable.CurrentKey" sub-event, inside a "(HashTable) For each key" event), then put the HashTable.CurrentValue in its 'destroyed' variable.

Makes sense?. This doesn't seem to work.

I checked the debugger and it seems that each time I leave the room and go back to it, the bricks get a brand new/different UID, so how can I keep track of each individual brick and it's state?. Am I missing a feature that would make all this much easier?. Thanks in advance.
B
5
G
2
Posts: 46
Reputation: 817

Post » Thu Mar 04, 2010 8:34 am

Ok, since half the users say save/load is bugged, and the other half say it's fine to use except with certain third party plugins that are bugged. Why not a compromise?

Setup an event that saves a version of the undamaged level, in this case where none of the bricks have been destroyed, using the save to ONLY save the undamaged bricks (and other things you want to persist like that, depends on what else you have in mind but we'll stick with just bricks for this example). Then when the player starts the game, upon entering that level, he/she automatically loads that saved file. Because it's only loading certain things and not expected to load everything, then badly behaved plugins shouldn't have an issue with it.

When the player leaves the level as per your example. Those bricks are once again saved in their new state, to the same file. So when the player returns, bingo, the level is how they left it, and previously destroyed bricks, remain destroyed.

Then use a value inside an ini file or registry key (you'll need an installer such as Inno or Nullsoft to create the registry key, but then construct can edit it afterwards) to tell it if it's supposed to be a new game or not, or alternatively, a profile type setup. In which case a new undamaged version of a save file is saved prior to the player getting their grubby hands on the level (like during a "loading level 1" message, so they don't notice it's saving/loading anything). Then in the case of a new game, all the bricks will be untouched, ready to be destroyed again.

That make sense?
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Thu Mar 04, 2010 10:34 am

yep, you can't guarantee that UIDs will ever be the same when an object is recreated. If fact, that would be very surprising.

[quote="Lost my Keys":1skopkww]Setup an event that saves a version of the undamaged level, in this case where none of the bricks have been destroyed, using the save to ONLY save the undamaged bricks (and other things you want to persist like that, depends on what else you have in mind but we'll stick with just bricks for this example). [/quote:1skopkww]

This is a good idea.

I did something something less sophisticated in my games. I save the x and y location along with the room name in a global array and then when I returned to rooms I redestroyed all of those objects that matched. p.s. Part4 of the adventure tutorial specifically addresses these issues of changing layouts so it might help you to take a look.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Thu Mar 04, 2010 9:25 pm

Thanks for the replies. I got the saving thing working, for now, maybe I'll come back asking more questions when I get in trouble again.

Thanks :D
B
5
G
2
Posts: 46
Reputation: 817


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests