Page 1 of 1

Can JSON contain self-made Function some way?

Posted: Thu May 08, 2025 5:59 pm
by Bugala
I am trying to make an all purpose StoryEngine that would be scriptable in JSON-format.

What I am wondering is if there is a way to execute some Hollywood code, by adding it to JSON-format.

As in, lets take two different scenarios.

I might want to make a special mission where enemy ship needs to be destroyed, when that ship is destroyed, it should execute following code:

Code: Select all

{
  "onComplete": [
    {"HollywoodCode": "Function() GetReward(100) EndFunction"},
  ]
}
And then there could be another game where when winning it is supposed to unlock a card:

Code: Select all

{
  "onWin": [
    {"HollywoodCode": "Function() UnlockCard("Special1") EndFunction"},
  ]
}
I can of course achieve this by having something like:

Code: Select all

{
  "onComplete": [
    {"HollywoodFunc": "GetReward", "100"},
  ]
}
And then in the games code telling that when script says a HollywoodFunc and uses arg "GetReward" then it is supposed to call "GetReward()"-func.

But in ideal case I wouldn't need to tell the game anything about the JSON-script, but could simply add commands through JSON, without the game having any knowledge about them.

But is this possible? or do I just have to have it scripted in to the game code that HollywoodFunc "X" refers to FunctionX, and HollywoodFunc "Y" refers to HollywoodFuncY?

Re: Can JSON contain self-made Function some way?

Posted: Thu May 08, 2025 6:36 pm
by plouf
,i dont think it can, somethink like that is also balance between licence freedom.
That to prohibit ppl from writing a "languange" which is basicaly a simple wrapper out of other works ;-)

Your question thought is legimate, these thinks are done by embedded a scripting languange like.. lua :-) or python or..
But its easy out of the box in hollywood, simce must be in C in a plugin. Which would be a nice idea btw :-)

The easiest and best idea imho is to make your own interpreter languange, as thinks you would need are mimimal.
So if you found a bg_createmap(20,10) will make a new stage 20*10 size

Thats would be my approach

Re: Can JSON contain self-made Function some way?

Posted: Thu May 08, 2025 9:44 pm
by Bugala
plouf wrote: Thu May 08, 2025 6:36 pm ,i dont think it can, somethink like that is also balance between licence freedom.
That to prohibit ppl from writing a "languange" which is basicaly a simple wrapper out of other works ;-)
This is why I too was thinking it is probably not doable.

Re: Can JSON contain self-made Function some way?

Posted: Sun May 11, 2025 7:19 pm
by airsoftsoftwair
Bugala wrote: Thu May 08, 2025 9:44 pm This is why I too was thinking it is probably not doable.
It's not just that. Supporting such a thing would also require the Hollywood runtime to include the whole Hollywood compiler as well. Currently the Hollywood runtime can only run compiled bytecode, it cannot compile source code into bytecode. This needs the Hollywood compiler. But it is possible to embed compiled code in JSONs, just as you can do with WriteFunction() and ReadFunction().