Save and Load Items

Hi,

I am trying to save and load the items, the problem I have is that I can’t seem to find a solution to save the coordinates into a file. I made it so the items are actually multiple animations, but it detects just one.

Image is of object “items”.

This image shows the save game conditions, the first part is fine, it is to save the player position.
The second part starts with repeat for each objects, and there is my problem. Even when I have 2 items on the tile map it saves only one instance of the object items.

This is the Load conditions,

Any help is greatly appreciated.

Now, I just briefly looked over, (I am short on ime) but to me, it looks like the save_items info is overwriting itself (I didn’t notice it being appended anywhere), which would explain why it only works for one, it just rewrites the coordinates over itself? Could this be the issue? Maybe try a sperate saveitems2.txt for the wood, and if that works, then you can confirm the info is being rewritten over itself.

1 Like

I would agree with snobunni, it looks like some of the stuff is overwriting itself.

That said, I’d also say your save/load method is substantially more complex than needed by using string find expressions. I’d recommend just building out a global structure variable named “GameState” and then using that to store all of your variable info that you use in the game. You can then just save that structure variable and load it when needed without having to do a bunch of specialized seeking, since it’ll already be the game logic used.

You can see an example of this in the advanced save/load tutorial on the main youtube

(Method works for storage events or filesystem events)

1 Like

Level editor - a game example from the GDevelop game making app | GDevelop
Not using the file system but maybe the logic can help.

Hi,

Sorry to bother you again,

I tried the first solution, overwriting advice, it didn’t work as intended, and yes it is hard to follow with, there might be more problems than just that, so I kept it away for now, since you said there is a more reliable solution.

I have followed the tutorial and did as it said, created a global variable structure, and added a sub variable named Items as I want to save Carrot and Wood position, I have a bit of struggle now … how to “assign” a variable, so it knows which object to save and load, I mean how to connect this variable “Items” with this two animations, Can you give me an example ?
And do I need to separate it into two items or can I keep it as it is ?



And this are the items I meant ( I don’t know if it is the right way to do it, but I used animations)

Thanks

So, you can make a structure under items, have one “carrots” and one “wood”
Under those, make a structure for the variables attached (ie X, Y, animation, etc…)
you could have a variable in there that goes up by one called “carrot count” as an example, which increase everytime the character picks up a carrot. I hope that helps a bit…

so it would be something like if char picks up carrt, then change the GlobalVariable allmyvars.items.carrots.carrotcount add 1 assuming the entirety of the variables are held in one main structure titled “allmyvars” if you put them under one main variable like in the tut SilverStreak suggested. Hope that makes sense :slight_smile:

3 Likes

Thanks,

I watched the video few times and tried to recreate this post that you have gaved me, with some manipulation of the conditions and rewriting the code,

I made it work, the items I had were displaying and loading up correctly.
I am posting my code below.


-||-

2 Likes

Totally off topic but
How do I set my game up so that once it’s published, players can use most of the features for free, but to get access to extra features they have to pay for a subscription. And when the subscription runs out it only allows them to use the free version. And only that one player can use the access he has from the subscription, I don’t want the player to be able to share the game. FYI, yes I understand variables, etc.
Please help?

Hey, you are replying to a year old post. You should be creating a new post, but anyways to answer your question. You can either finish a demo version, and export the file. Then simply moving on the same project. That way each exports will stay diffrent. One as paid, and one free demo. There is also a plugin for ingame micro transactions for ingame items still keeping the game free but selling items directly in your game. I am not sure if there is any subscription based integration yet, but that could be done custom with firebase storage, creating accounts for each user, and linking ingame payment plugin, having custom code behind to check on which date user paid and end change his status on end of " subscription " asking the user to pay again. I think it could work that way. There sure could be an easier solution, but with firebase you get also storage of transaction, and manual removal / upgrade of users and much more.