Story Format: Sugarcube 2.36.1
Basically I want to have a widget like <<flavour “Iron Sword”>> that prints the description of the “Iron Sword” item, or <<dialogue “Markus” 2>> that prints the second dialogue option for the character “Markus”. If it were possible to do this with an internal passage, then I’d like to do that, but as far as I can tell that’s not really possible without saving it in a variable. Which would work, but as I want to have a short description of every item and character, which may (and probably will) number in the hundreds, I’m concerned about saving too much data as a variable.
So my idea was then to try and load external JSON files, as and when I needed to do so, but every attempt to frankenstein together code I found online totally failed. They all were more about initialising variables once at the beginning of the game, though, rather than frequently accessing files like I want to.
I recognise this is probably a very specific ask, but any help that anyone could provide would be greatly appreciated. Or even just to tell me that I should probably scale back my expectations a little.
I can’t help on importing external files but use widgets extensively for flavor text. If you want Markus to just make a random comment, you could use a single widget and use the random macro with a simple if/elseif. If you want him to make specific comment it would be easier to just write it in.
Markus make a random comment
<<set _num = random(1,4)>>
<<if _num == 1>>
The weather is really nice today.
<<elseif _num == 2>>
My back is hurting today.
<<elseif _num == 3>>
I'm hungry for some apple pie.
I didn't get enough sleep last night.
Markus make a comment based on what passage your in
<<if passage() is "forest">>
Be careful, there could be wolves in this forest.
<<elseif passage() is "town">>
I here there is a magic shop in town.
Wonder if anything exciting will happen here.
Do you know how widgets are actually stored? Like are they stored in localstorage, which is where Story variables are stored (and the overfilling of which I was trying to avoid in the first place) or are they sort of just accessed as and when they’re needed? If it’s the latter, then they’ll actually be perfect. It’s not that I want to use external files - rather, I hadn’t come across a way of managing them internally.
Earlier today, I started setting up some python code and planning some data structures to move all the data about items, weapons etc. to the setup object, as none of that needs to change at all, so that’s all sorted, at least.
They don’t use local storage the way story variables do, I’m sure Greyelf or Madexile can explain how they work in depth
Widgets aren’t “stored” at all, really. Well, I guess they are tenchically in memory, if that’s what you mean, but they certainly aren’t in local storage or anything like that. They are created at runtime.
So I’m totally fine to make as many widgets as I want to? If so that’s definitely how I’ll manage flavour text, thank you