Howdy, Stranger!

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

Is there any alternative to the 'replace' macro (click - change text + changing "set" each time)

edited August 2015 in Help! with 2.0
Hello!

So far I'm getting my head around the more advanced techniques of coding, and already feel like I'm making excellent progress, although currently I feel as though I am at an impasse.

I have seen this particular tool implemented in other stories, where you click on a non-link type variable and (I'm not sure if this changes any 'Set' variables or not) it changes the highlighted text, which can be changed back and forth between the two (could there be more for implementation?) with ease.

E.G.

I feel 'good'*click*'bad' today.

"GOOD"/"BAD" being the variable to change.

On the Sugarcube 2 macro page, I tested the macro for the replace tool (thinking that this was the most viable option), and I can change the text from something to something else, but changing it back is a different story. It seems to be only able to change text that isn't part of the actual <<'click'>> either (or from what I tried at least). This also isn't my first choice in this area as it takes a troublesome amount of coding to implement for something that actually sounds rather simple in practice.

Is there any alternative to this method? Not sure if it's just me, or that I'm using the wrong macro.

Thanks guys.

Comments

  • If all you need to do is to cycle through some text and change a $variable to the text you're cycling through, then you probably want to use the <<cyclinglink>> macro, which is an optional add-on. If you're actually using SugarCube 2, then you can find the download you need on its website under Downloads > Add-ons (it's the first link under Add-ons).

    Usage would look something like this:
    I feel <<cyclinglink "$feel" "good" "bad">> today.
    
    The corresponding link will cycle between "good" and "bad", setting $feel appropriately (n.b. note the quotes around $feel; while you should not normally quote $variables given to macros, the quotes here are required).
  • Hey Madexile, thanks for the speedy response :D

    I checked, and I realize this sounds daft, but I didn't realize that sugar cube is always 1x, regardless of whether you had twine 2 or not. Obviously you can change it with the add format function however (as I had found), but it seems to take a significant amount of time with 'loading' on the add new format page where sugar cube 2.0 is concerned.

    In fact I don't think it ever finishes loading x) anyhow I closed that window because I thought to myself 'it *MUST* be done by now!' Afterwards, I checked to see if the cycling link macro would implement itself and it constantly and stubbornly refused, stating that 'sugarcube 2.0 must be installed.' Even though it's right there in the 'Story format' window.

    Seriously have no idea why this is happening. I even cleared out my stories in twine (after publishing them of course) in the hopes that this trouble would cease, but no, it continues relentlessly! I know this is a somewhat unrelated issue, but yet again I feel like a like a helpless idiot who has no idea what he's doing. Please help me!
  • To add SugarCube 2, I assume you followed the instructions? Where did you unzip the package to and what did you use for the URI?
  • Sorry was away from my computer for a while. Yes, I followed all of the instructions to the letter.

    My file path on twine 2 import format is;

    file:///C:/Users/RaddersHQ/My Documents/Twine/StoryFormats/SugarCube-2/format.js

    Even after coming back to it after a while it still does the same routine, even after turning off the anti virus. Should I just reinstall Twine 2 or is there another way?
  • Alright. After wiping out my Twine 2 (v2.0.8) local app cache and trying to attempting to add SugarCube 2 fresh, I've run into the same issue you have, so apparently that's broken in Twine 2 now as well. Bother.

    Regardless, if you let it churn for a bit, it does actually seem to add the story format, even though it never completes properly (I simply closed the Formats window after 15 seconds or so). If you open the Formats window now to look at your available story formats, do you actually see SugarCube 2 or no?

    If you do see it, then it probably (maybe) did get installed. You should simply be able to go to your story, open its edit menu and select Change Story Format, and then check SugarCube 2.
  • I remember when I was first trying to get it to work it did actually add Sugarcube 2 each time, but whenever I tried to activate the 'Cycling link' macro for javascript it came up with a rather large error.

    More recently I've noticed that changing the story format to Sugarcube 2 also changes the format and layout of the story/page, regardless of what the stylesheet says (tried and tested).

    Is there perhaps an older version then that doesn't have this particular issue?
  • RaddersHQ wrote: »
    I remember when I was first trying to get it to work it did actually add Sugarcube 2 each time, but whenever I tried to activate the 'Cycling link' macro for javascript it came up with a rather large error.
    Which was…?

    RaddersHQ wrote: »
    More recently I've noticed that changing the story format to Sugarcube 2 also changes the format and layout of the story/page, regardless of what the stylesheet says (tried and tested).
    There are differences between SugarCube 1.x and 2.x, so if you've made significant changes to the layout based on SugarCube 1.x, then you'll either need to stick with 1.x or make the necessary style updates for 2.x.

    If staying on 1.x would be easier, then you can find a SugarCube 1.x compatible <<cyclinglink>> download on its website under Downloads > Add-ons (the original link from one of my earlier posts was to SugarCube 2's website, since that's what you'd stated you were using at the time).

    If you'd like to stick with 2.x, then it would probably be easier to just show your styles here, so I can suggest updates (though looking at the SugarCube 2.x CSS docs might help; there's not much to them, currently, so maybe not).

    RaddersHQ wrote: »
    Is there perhaps an older version then that doesn't have this particular issue?
    Older version of what, which doesn't have which issue? Multiple things have been discussed and it's not clear which you're referring to here.
  • When I said Older version, I had meant an older version of the current iteration of sugarcube 2x, as it was not certain what was causing this infinite loading problem.. I was just troubleshooting anyway, forgive me.
    There are differences between SugarCube 1.x and 2.x, so if you've made significant changes to the layout based on SugarCube 1.x, then you'll either need to stick with 1.x or make the necessary style updates for 2.x.

    If staying on 1.x would be easier, then you can find a SugarCube 1.x compatible <<cyclinglink>> download on its website under Downloads > Add-ons (the original link from one of my earlier posts was to SugarCube 2's website, since that's what you'd stated you were using at the time).

    If you'd like to stick with 2.x, then it would probably be easier to just show your styles here, so I can suggest updates (though looking at the SugarCube 2.x CSS docs might help; there's not much to them, currently, so maybe not).

    Well that's annoying.. Never mind, think I'll stick with Sugarcube 1 then, unless there's any particular point that would make it worth switching to 2.x?
    Which was…?

    http://twinery.org/forum/utility/thumbnail/687/Uploader/7a/01567e7110d3054dacbef7a3e99209.jpg

    Just tried installing the one you gave me from that link and it came up with that. The last one came up with something that was, if not identical, very similar.
  • RaddersHQ wrote: »
    Just tried installing the one you gave me from that link and it came up with that. The last one came up with something that was, if not identical, very similar.
    I don't know exactly what you did to produce that error, but you're doing it wrong.

    You copy the contents of the cyclinglink-macro.min.js file and paste it into the Story JavaScript (and had there been a CSS file, its contents would go into the Story Stylesheet).
  • edited August 2015
    Brilliant! I had wondered why it wasn't working x) Thank you :D

    Feel like a fool of epic proportions now, but it was an honest mistake..

    I did quite like the UI bar of Sugarcube 2, not sure if that could be implemented in 1 but It's making me tempted to switch over if not.

    Might end up switching one day anyway but we'll see x) one thing at a time first I think.

    Just a quick query, I have a cycling link like this;

    <<set $Skills to 10>> $Skills </b>

    <<cyclinglink "$Charisma" "Mysterious" "Introvert" "Sociable">>

    <<set "$Charisma" to {"Introvert", "Sociable"}>>

    <<if $Charisma ["Sociable"] is true>>

    <<set $Skills to - 1>>

    <<endif>>

    <<if $Charisma ["Introvert"] is true>>

    <<set $Skills to + 1>>

    <<endif>>

    Tested this, but it didn't work. Of course it's been about a week or so since I last used twine macro so I may be a little rusty x) could you help me fix it? Just know it would take me ages otherwise :S

    If you have the time yourself of course :)

    Thanks again Mad Exile!

  • edited August 2015
    First. You cannot do all of that in one passage with <<cyclinglink>>. The <<if>> macros have already completed by the time the passage is displayed to the player. They'll need to go into your followup passage.

    Also, if you wanted the value of $Skills to be dynamically updated on the page when the player cycles through the possible values of $Charisma, then this isn't going to work as-is (again, because the <<if>> macros have already completed before the player is presented with the <<cyclinglink>>). There are ways to do that sort of thing, however, they're a bit more involved.

    RaddersHQ wrote: »
    <<cyclinglink "$Charisma" "Mysterious" "Introvert" "Sociable">>
    
    <<set "$Charisma" to {"Introvert", "Sociable"}>>
    
    You do not quote $variables in a <<set>> (you generally do not quote $variables period). The only times you should quote $variables are generally noted in the docs of the macro in question.

    What are you attempting to initialize $Charisma to and why are you attempting to initialize it after the call to <<cyclinglink>>? You use the object literal curly braces, but then provide no property names as if it were an array. I'm assuming you were trying for an array, but confused curly braces for square brackets. Regardless, you likely do not need the <<set>> at all.

    RaddersHQ wrote: »
    <<if $Charisma ["Sociable"] is true>>
    
    <<set $Skills to - 1>>
    
    <<endif>>
    
    <<if $Charisma ["Introvert"] is true>>
    
    <<set $Skills to + 1>>
    
    <<endif>>
    
    Do not test a boolean variable for (in)equality to the boolean literals. The expression you give to the <<if>> macro is treated as a conditional expression (i.e. it all boils down to a boolean value in the end), so simply use the variable as the expression.

    Beyond that, the value of $Charisma is a string, not a boolean, so your conditional expression is erroneous anyway.

    I'm assuming you were trying to raise/lower the value of $Skills there, rather than simply setting it to 1/-1. If so, that's not how you do it.


    Try this for the first passage:
    <<cyclinglink "$Charisma" "Mysterious" "Introvert" "Sociable">>
    
    [[Next|Follow On]]
    
    Try this for the follow on passage:
    <<silently>>
    <<set $Skills to 10>>
    <<if $Charisma is "Sociable">>
    	<<set $Skills to $Skills - 1>>
    <<elseif $Charisma is "Introvert">>
    	<<set $Skills to $Skills + 1>>
    <</if>>
    <<silently>>\
    Other stuff here….
    
    There are more concise ways to raise/lower the value of $Skills, especially if you simply want to increment/decrement it, but that will suffice for this example.
  • Hey thanks for the response :)

    It's been very useful in order to ascertain the next steps in my project, and honestly, I doubt I could have gotten much further without your help :).

    After brainstorming for a bit and playing around with different ideas, I felt as though 3 different variables for each stat simply did not bring enough variety or individuality to the table from a player's POV.

    So, In order to combat this issue I have implemented a new system which merely implements numbered stats instead; e.g 'Introvert' Would now be 8 out of a stats page maximum of 15 and a default of 10.

    This new system somewhat rends the 'cycling link' system obsolete, but now I face a new challenge..

    I've seen a post on here about a similar process; whereby each "Stats" number would be raised or lowered on either side of the text, but I was wondering whether this would all be implementable into one passage, with the 'RAISE' and 'LOWER' integers Raising/Lowering the number of the appropriate Stat and Skill points to allocate, or whether I would have to create identical passages with a 0 second transition in order to make it appear as though it is the same page.

    Thanks again, every bit of help in these endeavors do not go forgotten :)
  • For those struggling to add SugarCube 2 as a new format, I found the way to do it was to use a URL style reference to the file that you wanted; for example:

    file://C:/SugarCube-2/format.js

    Rather than C:\SugarCube-2\format.js, which seems to leave it hanging.

    Good luck!
  • TeamDGL wrote: »
    For those struggling to add SugarCube 2 as a new format, I found the way to do it was to use a URL style reference to the file that you wanted
    This information is also available in the Local Installation section of the Twine 2 Guide.
Sign In or Register to comment.