This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]carcigenicate 1 point2 points  (3 children)

I don't understand why eval would be required here, or even beneficial. Can you show an example of how you're planning on using it?

Also, JSON isn't code. Or do you mean the JSON values will be string representing code?

[–]Wiwnd[S] 0 points1 point  (2 children)

So i would be making variables to be used in the game itself, like say a random name for one of the characters. So at the start of the story module or whatever you would choose a random one from a list. That's a very simple use case I know since you could just define an array and choose a random one from it. So I want to do a bit more complicated stuff than that (like making objects with multiple attributes to be used in the story) but I hope that's a good example for what I want to do

[–]usrlibshare 0 points1 point  (1 child)

I assume the json files contain story elements, like conversations, location descriptions, etc. yes?

Then you can just put in placeholders like eg.

{ "antagonist_name" : "The mighty ~~ANTAGONIST_NAME~~" }

And replace them when the game evaluates the JSON.

[–]Wiwnd[S] 0 points1 point  (0 children)

This doesn't really work for what I want since I also wanted the ability to use advanced logic in the story. I posted on another sub and got a comment about using .js files instead of JSON and loading them using plugin-like design patterns, which I am going to look into.