Is it possible to load external data and use it temporarily?

Twine Version:2.3.16
Story Format: Sugarcube 2.36.1

Hi there,

My plan for my project was to have a massive ‘world’ with potentially hundreds of characters that can all join your party and have their own ‘flavour text’ and dialogue that can be dropped into generic passages. I want to be able to load external data for stuff like flavour text and dialogue. I’m reasonably familiar with Sugarcube by now, as I’ve done a couple of practice projects, but I don’t really know Javascript and a lot of what I’ve been doing on that front is frankensteined together from snippets I find online. This is the first major roadblock I’ve run into.

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.

Many thanks.

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

<<widget "Markusrand">>
<<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.
<<else>>
I didn't get enough sleep last night.
<</if>>
<</widget>>

Markus make a comment based on what passage your in

<<widget "Markusrandpassage">>
<<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.
<<else>>  
Wonder if anything exciting will happen here.
<</if>>
<</widget>>
1 Like

Thank you.

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

1 Like

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 :slight_smile: