Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

Implementing and editing a complex object (Sugarcube)

$
0
0
Alright, so let me begin with an "I'm fairly new to Twine and most of my shenanigans so far have been tinkering. This is no exception."

So, let's say I have an object $car. A car is not made up of just one object, but of many.
So a $car would have four $wheels, one $engine, one $trunk and maybe five $seats, among other things.
Each of those $wheels, $seats, etc, would be its own object.
So we'd have something like
<<set $wheel to {
tyre : "michelin",
tyreDurability : 10
}>>
<<set $engine to {
brand : "mitsubishi",
speed : 10
}>>
/%Rest of fluff here%/
<<set $car to {
wheels : [$wheel, $wheel, $wheel, $wheel],
engine : $engine,
trunk : $trunk,
seats : [$seat, $seat, $seat, $seat, $seat]
}>>

So, my first question is: Is this the best way to implement a complex object in Twine? Is there a better way, and if so, what is that way?

Secondly, what would be the most efficient way to change parts of the car? Using
[[Accept the mechanic's offer|nextPassage][$car.engine.brand to "honda", $car.wheels[0].tyre to "square", ..., $car.wheels[3].tyre to "square"]]
takes up a huge amount of space in the passage and is very difficult to keep track of. It's easy to forget, say, a $car.wheels[2].tyreDurability to 17 when typing out about twenty other things. Additionally, if I wanted to have a cascading change, it's impossible to do that without typing it all out myself. For example, if I changed the car's overall brand from a Ford F-150 to a Reliant Robin, then in that very same section, I would have to change the engine, the wheels, etc. A better result would be that when I want to change the car's overall brand, I call a function that reads a global variable somewhere and changes anything that needs changing. Want to change the car's electronics? Function changes the GPS, Radio and heating system. Stuff like that.
I know what needs to be done, but I'm not sure how to best approach the code. Perhaps this is a result of my object being flawed in the first place, and I'm just too dumb to see it, haha.

If anyone has any ideas or any obvious stupidity on my part, it'd be great if you could help out.

Viewing all articles
Browse latest Browse all 1844

Trending Articles