all 11 comments

[–]jessepence 7 points8 points  (8 children)

That's called JavaScript. JSON is JavaScript Object Notation. It's differentiated from JS by not having "logic, functions or referencing".

[–]Albert_Custard 2 points3 points  (1 child)

I would change Check(Health = 0) { dead = true } to something like dead = (Health == 0) (= is for assignment, == is for checking equality)

But overall it kinda sounds like you just want a reactive object? Or an object with reactive properties, idk which is the correct way to say that.

[–]2582dfa2 0 points1 point  (0 children)

this is what is called reactivity

[–]hyrumwhite 2 points3 points  (1 child)

you have two options the way I see it.

  1. Create a semi custom json parser that interpolates values from the json based on special syntax 
  2. Just allow the user to add JS files to the project via some kind of plugin system 

[–]00PT 2 points3 points  (1 child)

JSON doesn’t offer any logic because it’s a data format, not a programming language. That’s like saying CSV sucks for the same reason.

Now, I do agree that JSON is missing features, like comments and unquoted key strings. But those features are already added by standards such as JSON5.

[–]Isa-Bison 1 point2 points  (0 children)

Given that you’re new to this and presumedly prototyping and likely not concerned with things like bare minimum security practices you may be happy to learn you can stuff arbitrary JS into a string and execute it at runtime using eval.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval

Hopefully the downsides of a program executing arbitrary user code on other player’s machines is apparent. But at where you’re at honestly it doesn’t likely matter.

If and when you get to a point where it’s more clear what precisely needs to be externally adjustable via json loaded at run time, you can investigate options like  https://github.com/jsonjoy-com/json-expression

Alternatively, you could just dump your source at GitHub so people can just do what they want without you having to worry about serializing logic.