I ran into a problem with an RPG I’m making and I was wondering if anyone could help me:
When I get a gem the gem gets deleted. However, when I leave the scene and come back I don’t want that specific gem to still be there. I still want the ones that I haven’t got to be there. The only way I know how to do is to make separate gems (gem1, gem2, gem3) and separate global variables to connect to each gem. For example, if I get gem1, global variable “doesgem1exist” becomes 1. When global variable “doesgem1exist” is 1, delete object gem1. That way if I leave and come back gem1 will be gone. If I get gem2, global variable “doesgem2exist” becomes 1. If global variable “doesgem2exist” is 1, delete gem2. And so on. Is there an easier way to do this? There could be hundreds of gems in this game by the time it’s finished and I don’t want to keep repeating this process and creating hundreds of separate gem objects and separate events for each one.
Hi. So you need a respawn of the gem each time you restart the scene? Why you can not just create it at the beginning of the scene?
Replace “Change the scene” by “Pause and start a new scene”.
To make sure I understand the goal here before I give you poor guidance:
- You have numerous scenes (more than 1) with Gems on them.
- You want to be able to track “gem obtained” for each gem
- You may add or remove more gems later, and don’t want to have to create/remove global variables for each
Is all of the above correct?
Thanks @jack I’ll see if that works but there may be times when I don’t want to pause everything about the scene.
Jack’s suggestion will work perfectly if you have only 1 scene, so if you only have 1 use case, that’ll definitely be easier.
However, I don’t believe you can pause more than 1 scene currently, but I could be wrong.
If you do need this for more than one scene, then at a high level I believe what you’re wanting to do is:
- Count how many gems are in the scene
- Give each gem a unique ID
- For each gem, store a global variable that tracks if it has been picked up.
- For each gem, if it has been picked up, destroy it.
- Additionally, track if 1 and 2 have been done before, so it doesn’t lead to resetting the gems when the scene is reloaded.
There are a few different parts to this, however you can see something very close to this in my Metroidvania Minimap example: GDevelop Dynamic Map by Silver-Streak
You’re going to need to tweak my method a bit, so what I’d recommend:
- Create some global structure variables.
- Something like SaveInfo as the parent, with Zone1, Zone2, Zone3, etc as child variables. These will be where you store your information (and you can even use SaveInfo to store other information that might be relevant to your save game.).
- Make sure each child variable is a structure variable that has a AlreadyCounted childvariable, set to 0.
- Next we’ll set up the parent event to make sure the “configuring” only happens once, at the start of the scene:
At the beginning of the scene | (No Action)
- Next we’ll set up a subevent to this parent to make sure we’re only doing this if the current scene HAS NOT been set up already:
The Global Variable SaveInfo.Zone1.AlreadyCounted = 0 | Change the Global Variable SaveInfo.Zone1.GemCount: set to "Count(GemObjectNameHere)"
- Then we’ll deal with the actual gems, by adding a For Each (GemObjectName) subevent to the above subevent.
For the sake of visibility, we will then add a subevent to the For Each:
(No condition) | Change the Global Variable SaveInfo.Zone1.CurrentCount: add 1 // This just gives us a counter to use for the next 2 events.
| Change the variable ID of GemObjectName: set to GlobalVariable(SaveInfo.Zone1.CurrentCount) // This adds an ID variable to the current gem.
| Change the Global Variable SaveInfo.Zone1[ToString(GlobalVariable(SaveInfo.Zone1.CurrentCount))].ID: set to GlobalVariable(SaveInfo.Zone1.CurrentCount) // This adds a matching Child Variable and ID variable to the global variables.
- We will then add a final subevent to the For Each:
GlobalVariable(SaveInfo.Zone1.CurrentCount) = GlobalVariable(SaveInfo.Zone1.GemCount) | Change the Global Variable SaveInfo.Zone1.AlreadyCounted: set to 1 // This is using the "Compare two numbers" condition.
All of the above are placeholder names, use whatever works for your game.
- There are two other events you’ll need:
- In your “pickup gem” event, you need to add an action
Your pickup gem event stuff here | Change the GlobalVariable SaveInfo.Zone1[ToString(GemObjectNameHere.Variable(ID)].PickedUp: set to 1
- In a wholly separate For Each GemObject event (not subevent):
The Global Variable SaveInfo.Zone1[ToString(GemObjectNameHere.Variable(ID)].PickedUp | Destroy Object GemObject
This should accomplish what you’re looking for. The biggest “Gotcha” is dynamically accessing the Global variables that match your Gem’s ID variable. But this should work.
Hope this helps.
@Silver-Streak OK thank you very much!
Yes, there will probably be gems in most of my scenes.
I’m new to this program and I don’t understand some of what you’re saying yet but I tried to follow your steps anyway. It did not work. I must have done something wrong. Is there a tutorial on this somewhere?
Unfortunately, there isn’t a tutorial on this that I know of, because it’s doing some very advanced stuff ( (dynamically declaring variables via events rather than through the interface).
I might be able to further help, but you’d need to show a screenshot of your events in order for anyone to be able to debug it further.