Howdy, Stranger!

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

SugarCube: How to erase previous searched locations from probability.

I'm relatively new to the programming side but do have some basic idea on html, css and Javascript. I'm currently making a bit of a RPG on SugarCube. As I mentioned, I'd like to have multiple events that could happen as part of a passage you can revisit. I was able to make the basic idea work with if/else conditionals:

Exploring...
<<set $explore = random(99)>>Debug: $explore

<<if !$foundLocationA && !$foundLocationB>>
<<if $explore < 50>> Random Event
<<elseif $explore < 80>> Location A
<<else>> Location B
<</if>>
<<elseif $foundLocationA && !$foundLocationB>>
<<if $explore < 80>> Random Event
<<else>> Location B
<</if>>
<<elseif !$foundLocationA && $foundLocationB>>
<<if $explore < 70>> Random Event
<<else>> Location A
<</if>>
<<elseif $foundLocationA && $foundLocationB>>
Random Event
<</if>>

Basically if I wanted such that there are multiple events more than Random Event, B, C here; if I found A or B I will no longer be able to find it again (I have another passage for old locations). Going to location A and B will set the foundlocationA/B to true which unlocks it for old locations. Is there some easier way to do this? (someone mentioned me used nodes not sure how) This would drive me insane if I have to repeat this for Location A-Z.

Comments

  • First. You should always state the story format you're using and its version, because advice will tend to vary based on that information. Are you using SugarCube v2 or v1?

    Second. Please use the code tag when posting code or markup—it's C on the editor bar.


    If you're asking for a way to determine whether the player has been to a location, which doesn't require you to set a story variable, then you could use the visited family of functions to do so. Documentation:
    If you're asking about something else, you're going to need to clarify.
  • edited February 13
    Okay, for a start I did mention SugarCube right on the topic, but ya my bad not stating properly - version v2.12. It's my first time posting here, so I didn't notice the code snippet part. The functions does simplify the booleans, but I figured I'd just type it the usual way I do. What I wanted to do is to simplify that code so that I can set and eliminate probabilities. Oh, I'm coming at another approach at doing this although it doesn't allow me to control the probability of Location A/B events well:
    <<set $eventList = ["Location A", "Location B", "Location C"]>>\
    <<set $eventLink = $eventList.random()>>
    <<set $explore = random(99)>>Debug: $explore\
    <<if $explore < 30>>\
    	[[Exploring...->$eventLink]]
    <<else>> [[Random Event]]
    <</if>>
    

    Then delete it from the array when you enter the location. Anyways, I just can't quite wrap my head around writing some kind of efficient code for controlling those probabilities in the $eventList for this approach.
  • Sylphion wrote: »
    Okay, for a start I did mention SugarCube right on the topic, but ya my bad not stating properly - version v2.12.
    I caught the reference, which is why I emphasized the need for the version as well, because you really do need to state both, regardless of the story format used.

    Sylphion wrote: »
    […] Anyways, I just can't quite wrap my head around writing some kind of efficient code for controlling those probabilities in the $eventList for this approach.
    It would probably help by defining what kind of probabilities you're looking for here. In your original example each case had a unique set of probabilities, which does not lend itself to optimization.
  • Sylphion wrote: »
    […] Anyways, I just can't quite wrap my head around writing some kind of efficient code for controlling those probabilities in the $eventList for this approach.
    It would probably help by defining what kind of probabilities you're looking for here. In your original example each case had a unique set of probabilities, which does not lend itself to optimization.
    [/quote]

    Ya I guess I wasn't communicating what I want very well. Basically as a basic example for what I was writing at and didn't do it quite right was that. Location A, B ,C certain probabilities of happening, lets say 25% 15% 10 % while the remaining 50% would be Random Events. If you gone to any of Location A, B, C etc. it would be eliminated and the probabilities of the rest remains the same while the random events increase by the one that has already happened. The array method, just evenly distributes the chance of A, B, C over 50% while the rest is Random. It doesn't Increase random unless I put it into the array itself which is still distributed evenly. Hope you get at what I'm trying to do. I'm not good at conveying it haha
  • Whoops. This kind of fell off my radar. Sorry about that.

    I've thrown together a skeleton of how you might do something like this. The core parts are JavaScript, since it's easier to do that way. I've attached the Twine 2 story archive, which you import into Twine 2, to this post.
  • @Sylphion
    WARNING: Do not mark the comment containing TheMadExile's skeleton as an Answer, even if it does solve your problem because that will cause the forum software to delete the attached file.
  • Simplest technique would be an array of 20 elements contains 5 As (25%), 3 B's (15%), 2 C's (10%) and 10 R's (50%). Pick one of the 20 slots. If it's not an R, replace all occurrences of that character with an R.

    Could well be what TheMadExile suggested, but I can't get his html attachement open (problem/restriction my end).
  • mykael wrote: »
    Could well be what TheMadExile suggested, […]
    Not quite.

    mykael wrote: »
    […] but I can't get his html attachement open (problem/restriction my end).
    You probably simply need to right-click the link and select the save as menu item—the actual name varies by browser: Save as…, Save link as…, Save target as…, etc.
Sign In or Register to comment.