Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Problem with qualified names

Hi, all!

I use Twine 2.1.3 and Sugarcube 2.18.0, and I have these two definitions:
<<set $spider = {
    name: "Araignee"
}>>
<<set $C01 = {
    opponent: $spider
}>>

I thought that <<print $C01.opponent.name>> would print "Araignee", but it doesn't. I'm told that opponent is undefined. How come?

Thanks in advance.

Comments

  • Your example works for me if I cut-n-paste your three macro calls into a new passage in the order they appear in your example and then run it.

    Are you sure you have correctly spelt the property names in your actual code?

    NOTE: Due to how the state of all known story variables get cloned/copied each time passage traversal occurs, the $spider variable and the $C01.opponent property will end up referencing two different but initially 'equal' objects.

    Once this occurs changing the value of $spider.name will not result in the value of $C01.opponent.name changing as well.
  • I'm sure of my spelling but with your second point you have something, greyelf. Actually my example was simplified. $spider was in a "Monsters" passage, and $C01 was in a "Combats" passage, both "linked" to "StoryInit" via <<include>> macros.

    I have deleted that and put everything in "StoryInit", and now that works. So, I have the workaround (the most important) but not the explanation. If <<include>> doesn't work in "StoryInit", that's a pity. I very much like a modular design for every project of mine, an old habit.

    Still, thanks for your help :-)
  • Actually my example was simplified.
    I tested the following passage structure the <<print>> macro still displays the correct value.

    note: Using TWEE notation, and the Start passage as the starting point.
    :: StoryInit
    <<include "Monsters">>
    <<include "Combats">>
    
    
    :: Monsters
    <<set $spider = {
        name: "Araignee"
    }>>
    
    
    :: Combats
    <<set $C01 = {
        opponent: $spider
    }>>
    
    
    :: Start
    <<print $C01.opponent.name>>
    
  • I have deleted that and put everything in "StoryInit", and now that works. So, I have the workaround (the most important) but not the explanation. If <<include>> doesn't work in "StoryInit", that's a pity. I very much like a modular design for every project of mine, an old habit.
    As noted by greyelf, <<include>> may be used within the StoryInit special passage without issue. It's likely that you either did have a misspelling somewhere, even if it was in the passage names passed to <<include>>, or you were including the passages in the wrong order. You, obviously, had something wrong somewhere, as there's no reason it shouldn't have worked if done correctly.
  • You're right : I was including my passages in the wrong order. And now, am I correct in assuming that the combination Twine + SugarCube works like a single-pass compiler? If so, I'll take that into account.
Sign In or Register to comment.