Saving Functions to JSON-file, what happens?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1395
Joined: Sun Feb 14, 2010 7:11 pm

Saving Functions to JSON-file, what happens?

Post 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.
User avatar
Juan Carlos
Posts: 933
Joined: Mon Sep 06, 2010 1:02 pm

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

Post 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.
jalih
Posts: 281
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

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

Post 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.
User avatar
airsoftsoftwair
Posts: 5850
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

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

Post 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.
Post Reply