It looks like you're new here. If you want to get involved, click one of these buttons!
<<set $relationshipJonas to false>> <<set $relationshipSamuel to false>> <<set $relationshipGrag to false>> <<set $relationshipDamian to false>> <<set $relationshipKelle to false>> <<set $jonasAffection to 0>> <<set $samuelAffection to 0>> <<set $gragAffection to 0>> <<set $damianAffection to 0>> <<set $kelleAffection to 0>> <<widget "relationships">>\ <<set $relationships to true>>\ <<nobr>> <<if $relationshipJonas>>\ Jonas Leaf: \<<if $jonasAffection gte 5>>\ <<print "Acquaintances">>\ <</if>> <<if $jonasAffection gte 10>>\ \<<print "Friends">> <</if>> <<if $jonasAffection gte 20>>\ <<print "Budding Romance">> <</if>> <<if $jonasAffection gte 30>>\ "In love." <<else>> "Stranger" <</if>> <</if>> <<if $relationshipSamuel>> Samuel Lighthill: \<<if $samuelAffection gte 5>>\ "Acquaintances" <</if>> <<if $samuelAffection gte 10>>\ "Friends" <</if>> <<if $samuelAffection gte 20>> "Budding Romance" <</if>> <<if $samuelAffection gte 30>> "In love." <<else>> "Stranger" <</if>> <</if>> <<if $relationshipGrag>> Grag: \<<if $gragAffection gte 5>>\ "Acquaintances" <</if>> <<if $gragAffection gte 10>>\ "Friends" <</if>> <<if $gragAffection gte 20>> "Budding Romance" <</if>> <<if $gragAffection gte 30>> "In love." <<else>> "Stranger" <</if>> <</if>> <<if $relationshipDamian>>\ Damian: \<<if $damianAffection gte 5>>\ <<print "Acquaintances">>\ <</if>> <<if $damianAffection gte 10>>\ \<<print "Friends">> <</if>> <<if $damianAffection gte 20>>\ <<print "Budding Romance">> <</if>> <<if $damianAffection gte 30>>\ "In love." <<else>> "Stranger" <</if>> <</if>> <<if $relationshipKelle>>\ Kelle: \<<if $kelleAffection gte 5>>\ <<print "Acquaintances">>\ <</if>> <<if $kelleAffection gte 10>>\ \<<print "Friends">> <</if>> <<if $kelleAffection gte 20>>\ <<print "Budding Romance">> <</if>> <<if $kelleAffection gte 30>>\ "In love." <<else>> "Stranger" <</if>> <</if>> <<endnobr>> <</widget>>
Comments
Second. Your <<if>> constructs are pretty abominable. They should probably look something like the following: (minus whitespace control and using Jonas as an example)
Moving on to suggestions on data structuring.
I would not recommend using an array, as you'd have do one of the following: remember which index belonged to which NPC, maintain a separate id-to-index mapping, or search though the array each time.
I'd suggest using either Maps or generic objects, the latter being simpler so let's go with them for now. For example: (in your StoryInit special passage) And an example of using it:
That said, using a separate property just to track whether or not the player has started a relationship with them is somewhat wasteful. You could simply initialize their affection to -1, which would signify no relationship. For example: And an example of using it: (only the very first line changes) When the player starts a relationship with an NPC, you simply set their affection to a value greater than -1. For example: You could make a widget for common operations like that as well. For example: The widget does assume that affection scores will be limited to whole numbers.
Moving on to your widget itself. It's fairly redundant, so I'd suggest using two widgets. One to check an individual NPC and another to invoke the first on all NPCs. For example:
I'm putting each widget inside it's own Passage.
And yes, I'm new to coding but it kept throwing <<else>> errors so that's why I ended up with what I did before. Thanks again
Oh. Okay. lol. Just NOT in the "Special" Passages, right.
Ah...well, Thanks. I already did fill it out
Heh, I may have been missing an extra }. lol. Sorry.
Thanks!
I've pasted the <<affection>>, <<relationship>>, and <<allrelationship>> widgets you've listed here into a standalone Passage called Relationships. I'm not sure where the error could be. Do I need to add another $arg[] or something?
Anyway, Thank you so much again hehe. It now works, more or less. I just have to figure out how to use it from studying your instructions.
I'm usign Twine 2.1.0b btw, now, if that has any bearing on the issues I'm having. if I have to, I will retroinstall 2.0.11 in case the new beta is the issue.
The Tag Names documentation shows the widget tag in lower-case where your example has it in mixed-case.
Widgets are another way to create macros, which is why you may get a "macro does not exist" error.
(This is in my Relationships Passage for Storymenu)
This above gets me a blank sheet (in the beginning) - since there's nothing to list yet and the <<back>> macro all the way down the page - as if it's listed all of the relationships in 'whitespace'. But I do not want to have to use the History button to return to the previous page. I've tried every other place - even in the code for the outputting of each relationship. In any other place it gives me a <<back>> link after EVERY relationship 'set', or every 'non-existent' relationship.
If you want, I can post the whole code again to see where I need to put the <<back>> macro.
Go ahead and post your current <<allrelationships>> widget and any widgets it invokes. I'll try to get back to you as soon as I can--if someone else doesn't first.
And currently, I have two StoryMenu Passages - Inventory and Relationships - the Inventory part doesn't need to be talked about since it works and all.
Onto the Relationships Passage - I basically have a <<allrelationships>> widget in it, and that's about it.
The new code regarding the phone # bit - I put phonestatus: false in each NPC's 'bio' datamap, so I can control when they actually 'show' the phone number when you select the relationship button. (In a dating sim, you do not always exchange phone numbers the moment you meet, or at the very end of the route. It varies.)
I was wondering where to put the <<back>> in the <<allrelationships>> widget if I can so it will not repeat itself inside the <<For>> loop. If I put it in the relationship widget after every 'if _npc.aff etcetc #' before the <<elseif>> then I have a <<back>> link after EACH relationship. I only want one <<back>> link ont hat page, but I don't want to output it after all the whitespace that I get from putting <<allrelationships>> in the Relationships Passage.
THe code will be updated sooner or later with more biographic info for each character, but it will be mainly output from the get-go later on. Btw, I don't really foresee more relationships than 1-2 in one route.
Now, about those line breaks….
You need to remove all line breaks from the <<allrelationships>> widget—because loop—and have the <<relationship>> widget generate an extra line break to compensate. Additionally, <<relationship>> should only generate line breaks when it is actually printing data—i.e. if it is not going to print an NPC's data, then it should not generate any output.
Beyond that, you're being horrifically redundant within the <<relationship>> widget. You should not be repeating the species and phone number displays within each affection case. Simply handle each data point once—i.e. affection THEN species THEN phone number THEN etc.
Try the following code: (tested and working as intended)
EDIT: As a stylistic suggestion, which also helps minimize the size of your serialized data, I'd use hasphone—or hasPhone—over phonestatus.
The problem is the code looks virtually indistinguishable from your previous copy, AND the one you just posted. I have no idea why THIS is happening. Help? lol. I greatly doubt it's to do with the $npcs Dataset I have. I have added a lot of stuff, but... it keeps only pointing to the <<allrelationships>> widget. Am I missing something obvious? The code looks identical to the one you posted earlier on in this thread.
EDIT:
I went through my $npcs dataset one character after another slowly - I eliminated anything that had an " or ' inside the main " "'s of each property and it's value. and made sure to put 'something' inside an "" if I don't have information for it yet. (essentialyl an "???" value.
I just have no idea what could be causing the issue. I doublechecked an earlier post you made with this <<allrelationships>> widget - and it looks absolutely identical, but when I play the game, I get some errors like this -
The above was basically doing <<set $npcs["jonas"].aff to 2>> essentially, and the other one was <<set $npcs["jonas".hasPhone to true>>. And both say they cannot find the $npcs code or think it's undefined for some reason. Am I missing an extra } or something?
I'll check again.
(Last edit)
Does TWINE have issues with multiple line property values? or Sugarcube?
As a result, this will work:
Whereas replacing $tmp and $i with _tmp and _i respectively will not. Even more annoyingly, there's no for-in operator in sugarcube, so you gotta use this clunky story variables workaround to iterate the keys at present. The big thing to remember here is if you access $i or $tmp from any subsequent widget, or anywhere else before the unset gets called, you will be overwriting the original value as nothing is being passed byval - it's all a reference to the same variable / object. So if you have nested iterative functions they all need unique names. Otherwise weirdness and unintended behavior will ensue.
Edit: sorry. I should adapt the code to your example. The above snippet is from my game. The code you want is:
Edit2:
There is another way to work around this, namely to write the iterating code in JS and pass the result back to twine in a story variable, such as an array containing strings to print (which is what I originally tried when the temp variables failed). It doesn't make for prettier code though and has just as many issues as the story variable workaround.
You are likely seeing that error because you've somehow broken value within the $npcs story variable or are doing something which is causing it to become unset.
This statement—and others—are making it sound like you're transcribing my examples by hand, rather than simply doing a copy/paste. I am, honestly, confused as to why you would do that.
Try placing <<relationship "jonas">> somewhere before the test of <<allrelationships>>. I'm betting you'll find that it yields an error as well—for the reason I've outlined above.
And that confirms my theory. That error means that $npcs has become undefined/null and is no longer an object. As to how you've broken it, no one can say without seeing the code.
Also, the <<set $npcs["jonas".hasPhone to true>> bit is missing a right square bracket—but that may have been a transcription error here (no copy/paste?).
SugarCube does not have issues with it—assuming your syntax is correct.
Twine does not have issues with any of your code, it's an IDE/compiler and has little to do with your code, save for compiling it into the story format.
Gryphbear is, as they noted in the opening post, using a recent version of SugarCube 2. The invocation <<relationship _npcIds[_i]>> does, in fact, pass the name of the NPC properly. Beyond that, as I noted in my previous post, this has all been tested by me and is working as intended.
You, personally, are, or were, using a pre-v1.0.0 version of SugarCube. Unless you have recently switched to SugarCube 2, then your specific issue is that you do not have access to SugarCube 2 temporary variables as they are a feature that was added in SugarCube v2.3.0.
For example, take the following code example: Within SugarCube ≥v2.3.0: It sets an special temporary variable which exists for the duration of the moment/turn within which it was created. It will be automatically unset at the beginning of the next moment/turn.
Within SugarCube <v2.3.0: It sets a JavaScript variable which is locally scoped to the <<set>> invocation.
TL;DR: What you've said is completely incorrect for the version of SugarCube 2 that Gryphbear is using. I'm not trying to be mean here, however, if you're going to attempt to help people, please try to ensure that the information you're passing on is correct—because passing on incorrect information helps absolutely no one.
Edit, for clarity:
Compiled in twine 1.4.1 with sc version v1.0.35 according to its header. I didn't test in Twine 2. I highly doubt any of the changes I've made to the header could have broken that functionality. This is very likely an issue with variable scope as temp variables work as intended within a single widget.
By the way, why does the header vers not match the release vers? Had me confused and double checked just to make 100% sure I got the newest.
According to Gryphbear, they are using SugarCube version 2.x, not version 1.x. Unless they gave the wrong version, you are barking up the wrong tree.
In my last post, I fully explained why the given code will not work in v1 and why it does in v2. Did you actually bother to read my post?
If you simply extracted that archive within your targets directory, then you probably simply did not change the story format of your project within Twine. So that it may coexist alongside SugarCube v1 installations, because some people need that ability, it has a different name/ID—directory in Twine 1, but the effect is the same. In Twine 1, you want: Story menu > Story Format > Sugarcube-2. As an additional note, you cannot simply change the story format and save, as Twine 1 does not flag that as a modification of the project, so it won't save the change until you modify something else.
/slinks away quietly
@TheMadExile - Thank you for helping out again. I went through the dataset for $npcs a few entries at a time, tested things, and finally weeded out the errors I had in it that I hadn't actually 'seen' right away. Like a set of " "'s inside one of the String Properties. Among others. It is working like a charm again, and all I need to do is tweak the relationship widget slowly, and the dataset for more clearer output. (Meaning, Polish the content inside the string values so it doesn't look so copy/pasted) As it is, it's a bit messy. Plus - I was copy/pasting, rather than transcribing.