Page 1 of 1

Saving Functions to JSON-file, what happens?

Posted: Fri Nov 14, 2025 5:19 pm
by Bugala
I just noticed I had used in some cases something like:

Code: Select all

Creature = {X=10, Y=10}

Function Creature.Move()
Creature.X = Creature.X + 1
Creature.Y = Creature.Y + 1
EndFunction

Function Creature:Bark()
Debugprint("Wof!")
EndFunction
When I save this as JSON file, and then load it later, will both these functions still work, or do I need to take something into account, or even separate data and functions so that I can just save/Load data and function are elsewhere.

Would have done this separation right from beginning, had I realised that my simple save/load method would include all these functions too, and now wondering If I should do that now afterwards, which luckily wouldnt be terribly big task.

Re: Saving Functions to JSON-file, what happens?

Posted: Sat Nov 15, 2025 11:31 am
by Juan Carlos
Using JSON files is complicated; I'm having trouble using this system to save the data for my project "Los Malditos del Valle del Cerro", but I don't know if it's an easy method to use.

Re: Saving Functions to JSON-file, what happens?

Posted: Sun Nov 16, 2025 6:50 am
by jalih
Standard JSON-parser should not support storing or evaluating code. Generally it's a bad idea and should only be done with trusted JSON, as it would allow injecting malicius code into your game.

Re: Saving Functions to JSON-file, what happens?

Posted: Sun Nov 16, 2025 6:34 pm
by airsoftsoftwair
jalih wrote: Sun Nov 16, 2025 6:50 am Standard JSON-parser should not support storing or evaluating code. Generally it's a bad idea and should only be done with trusted JSON, as it would allow injecting malicius code into your game.
Good point. It's still supported,though, but only as some proof of concept sort of. I'd also advise against using this.