Allowing the Reader To Set Attributes and Inventory At The Beginning

Hey all,
Super new to all this, maybe 3 weeks in, but very much enjoying learning to use the toolset. Like a lot of us I assume, I grew up playing the Lone Wolf Gamebooks and would like to recreate that experience inasmuch as possible. I was wondering first and foremost if it was possible to set up a situation where the reader can set their own attributes at the outset of an adventure from a pool of given points? I believe I've figured out how to set attributes in general using the documentation, although I'm sure there's likely a more elegant way to do it (and keeping in mind that I have very minimal exposure to javascript prior to this, so I'm mostly learning as I go). It looks something like this:

What's Your Strength? [[1]](start, strength=1) or [[2]](start, strength=2) or [[3]](start, strength=3)?
[[start]]:
Your Strength Score has been recorded.

This gets the job done, I suppose (although I'm not sure where this is saved or how to reference it later for attribute checks, there must be a way, or else why include it? I probably just haven't stumbled upon the answer yet), but I'm not sure how to limit the player to a specific pool of points that they can use to create a balanced character and not break the game by creating a super soldier. I've looked through the forums but much of what I've found about attributes is related to Quest, not squiffy, and unless I missed it, which is totally a possibility, the documentation doesn't really get this specific either. I'm also assuming that whatever the answer to this is will also work for creating an initial inventory out of a given set of items.

Any advice you guys might have to set me in the right direction would be so appreciated, thank you in advance. Looking forward to getting to know ya'll and play your games!


One way I could think of, though the code is a little unweildy.

[[start]]:
@set points = 20
@set strength = 1
@set speed = 1
@set int = 1

You have 20 points to spend on [[character creation]].

[[character creation]]:

You have {points} left to spend. What do you want to put them on?

Strength: {strength} {if points>0:[[+1]](character creation,strength+=1,points-=1)}
Intelligence: {int} {if points>0:[[+1]](character creation,int+=1,points-=1)}
Speed: {speed} {if points>0:[[+1]](character creation,speed+=1,points-=1)}

{if points=0:All ready? Now you can actually go to [[chapter 1]]!}

Thank you so much, I'll give this a shot!

update
This worked perfectly! And I'm led to believe that these values will be stored for attribute checks through the game? Also, I suppose it's probably too much to ask to have these values able to be displayed on demand, updated as is warranted? Functionally, it's not too hard (tho very cumbersome) to simply put an alert link in every section, but I'm thinking more like something similar to a "get" that pulls those relevant and updated data points from my first question into the alert. I know this may be swinging for the fences, but has anyone done anything like that? This is far from a deal breaker, of course, I'm prepared to simply create a companion pdf where you can track your stats manually, again a la lone wolf, but I guess while we're here I was hoping there was a way to do it completely digitally.


If you want to enter text (or even numeric information) you can do this. In one section...

Enter your first name:
<textarea id="text_first"></textarea>

And then in the following section...

    set("CaptFirst", jQuery("#text_first").val());

Just change text_first to other variables and you can enter first names, last, whatever you want. It makes a text box so the user can type stuff in.


wow, that was my next question! So you actually can create a name that is then tracked across the game so long as you reference it properly? That opens a ton of doors.


And I'm led to believe that these values will be stored for attribute checks through the game?

Yes; attributes will persist until you change them, or the player resets the game (which simply deletes all attributes, including the built in ones like _section, _output, and _transition).

Also, I suppose it's probably too much to ask to have these values able to be displayed on demand, updated as is warranted?

Do you mean allowing the player to see them whenever they want?
The most common way to do that is by putting some kind of status bar in the master section, so that it displays before every section the player visits. I've also written some code in the past for a sidebar, allowing you to have stuff displayed that doesn't interrupt the normal flow of your game's text.

I can try to look up the code if you want, I've got it saved somewhere (not sure where); but it's quite a large chunk of javascript to paste into the first section (abusing the _transition mechanic to ensure that the sidebar is recreated when loading a saved game)

I'm thinking more like something similar to a "get" that pulls those relevant and updated data points from my first question into the alert. I know this may be swinging for the fences, but has anyone done anything like that?

I'm afraid I don't understand the question there.
Once an attribute is saved you can display it or change it whenever you want. It remains there for the rest of the game.
You can display it in the game text by putting {attribute name}, or access it in Javascript using squiffy.get("attribute name"). That's the only kind of "get" I can think of.


@Mrangel, I apologize for the confusion, you actually more or less answered the question. What I was thinking of was a very basic type of alert that pops up, like in the documentation, so like:

Clicking this [link] will show an alert.

[link]:
    alert ("Hello!");
    
Text for the passage.

This alert would have the character details in it, so there would have to be some sort of other element needed in the javascript to pull that info into the pop-up bubble (hence the "get" I suppose). Im not sure if this is even possible or a madman's fever dream, and of course, it's kind of work-intensive since in order to make this happen, if it's even possible, you'd have to put that passage link in every section in order to achieve the desired effect. Put another way, before I hit the forums, the documentation was all I had to go off of, and this was my attempt at trying to expand off the docs to maybe make it do a little extra haha. You're way is much better tho, if you're able to find that code for the sidebar I'd be grateful (well, more so than I already am, thank you so much for the help) as it's a tool I'd love to have in my toolbox.


Thank you guys both for all your help! After some fidgeting with the code I was able to pull both your pieces of advice into one character creation element, creating more or less what I was looking to do. I know it seems like a small thing but at two weeks in, I'm basically excited enough to pop some champagne over it haha. Here's what I worked out:

Welcome To The Character Creation Screen

Please Enter Your First Name:
<textarea id="first_name"></textarea>

And Your Last Name:
<textarea id="last_name"></textarea><br>
<br>

@set points = 20
@set strength = 1
@set speed = 1
@set int = 1

Next, We'll set your [[attributes]]


[[attributes]]:
    set("CaptFirst", jQuery("#first_name").val());
    set("Captlast", jQuery("#last_name").val());

{CaptFirst}, you have {points} points to spend on strength, dexterity, and intelligence.  How do you want to spend them?

Strength: {strength} {if points>0:[[+1]](attributes,strength+=1,points-=1)}
Intelligence: {int} {if points>0:[[+1]](attributes,int+=1,points-=1)}
Speed: {speed} {if points>0:[[+1]](attributes,speed+=1,points-=1)}<br>
<br>
<br>
{if points=0:All ready? Now you can actually go to [[Chapter 1]]!}



[[Chapter 1]]:

I'm curious tho, does [[start]] actually matter, functionally? Does it do anything different than any other [[section]] header? I've seen @start used in the documentation, I guess if you intend to "Tarantino" around your story or something, but otherwise I'm not seeing the utility behind the section header version.


I don't think it makes a difference what you call the first section. Maybe it does start there. I always assume it begins at the top of the file.

I think what mrangel was mentioning is a master section - information below:

http://docs.textadventures.co.uk/squiffy/master.html

If you have stats, you can put it in here and it will pop up at every new section.


Naming a section differently doesn't make a difference; [[start]] is just what they call the first section in the examples.

@start tells the engine which section to start at. When you compile, if there isn't a @start line, one will be added in the background with the name of the first section in the file.

You mentioned adding a passage to every section. In my sidebar code, it also modifies some things so that a passage link anywhere can point to a passage in the master section (so the master section can contain stuff like [drink potion] links you might put in the sidebar)

For your alert example, you could do something like:

    alert("Hello, " + squiffy.get("CaptFirst"));

although this might be a bad idea because alert is deprecared and some browsers have been saying support for it will be dropped because it's so often abused (not sure if it actually happened yet)


OK; here's the most recent copy of the sidebar code I can find on the forums: https://textadventures.co.uk/forum/squiffy/topic/-1_dvogyqeuuuuolllotvg/sidebar-code-revisited#9e51bb82-fa83-4c81-8ae7-275d0f3e4e36

It starts with a section called initialise interface which sets up a whole bunch of black magic to change how Squiffy works, and at the end of that sends the player to the real first section with the line squiffy.story.go('first section'); (which you can change to the name of your actual first section)

There are two sections named sidebar container (the HTML to create the sidebar; edit this if you want to change the location or size of the popout box), and sidebar contents (which will be rendered again every time the player clicks on a link, so can be used to show the current stats or whatever you want).

It also modifies the way passages work, so that you can put passages in the master section. So you can do stuff like:

[[]]:
[drink potion]:
@dec num_potions
@set not thirsty

Yum!

This was originally so you could put inventory in the sidebar and have a [drink potion] link in it; but it will work if that passage link is in any section.

I think the code posted there should work fine :)


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums