Non-threaded

Forums » Advanced Editor Forum » Read Thread

Get help from the experts on variables, scripts, items, and other scary things.

Advanced Name and Variable

2 years ago

Hey all! I am trying to do something very specific and have tried a couple of things to make it work with coding, but my coding skill is not advanced enough. I was hoping someone else might be able to help.

I am choosing to use a different name in-game than the one offered in the guides. I am using the code from https://pastebin.com/QkJA0hHe. It works really well and I am able to provide an input field where players can type in the name they want to use.

The problem I am now facing, I am trying to find a code or create a code that checks the input field or the name typed into the input field and validate what that name is.

Let me explain further.

If a player types in a few specific names,  for instance, "Alice". I want to be able to check the name and see if it is Alice or confirm the value of the playerName is "Alice". What I would like to do is create a variable that I can use anywhere in the game to check the name. I want to create a variable "TNAME".

With this variable, I can assign a value based off the name the player uses. 

For example:

playerName = 'Alice' then %TNAME = 1
playerName = 'Bob' then %TNAME = 2

etc.

Once I have a variable that is defined by the player name entered, I can use it for specific unique interactions or storytelling. The player name could be anything, but if they happen to name their character "Alice" there will be a unique dialog later in the game, same with "Bob".

But I have to be able to define the variable %TNAME and have it interact with the name so when those unique parts of the store come up, I can check the value of %TNAME or define %TNAME based of the name chosen. I hope this all makes sense. I am not too interested current name in-game option presented in the guides, so hoping for more input if someone is smarter than me on this one. 

Advanced Name and Variable

2 years ago

I'm not completely sure what your question is, so I've got a few clarifying questions to try and understand what you're asking:

1) Can the player completely choose their own name digit by digit, or do you give them a list of pre-made names to choose from?  If you're giving them a specific list to choose from, you can just cause clicking on the "Alice" link to make %TNAME := 1.  If they can select their name digit by digit, then you'll need to use the code in this article to make the name show up every time you need it.

2) Correct me if I'm wrong, but you seem to be saying that depending on what name the character selects the player might get different choices or text made availiable to them.  You can do this pretty easily by having different values of %TNAME cause different text to show up as described in this article, and you can make certain links clickable or unclickable depending on the value of %TNAME.

3) I can't tell if this is what you mean, but you seem to be saying that you want the player to be able to enter a unique name digit-by-digit, but for specific pre-determined names such as "Alice", certain options and text in the story will be different.  There may be an easier way to do this, but what I would do is cause clicking on each successive digit in the name "Alice" add 1 to the variable %NAMEALICE.  So, when the player clicks on "a" on the first naming page, "%NAMEALICE := %NAMEALICE + 1", when the player clicks on "l" on the second page, "IF %NAMEALICE = 1 THEN %NAMEALICE := 1", and so on.  Then, when the player clicks on "e" on the fifth page, you can paste in the script box for that link "IF %NAMEALICE = 4 THEN %TNAME := 1".  However, since I don't know what system you are using for allowing the player to choose a name, this may not work.

4) Why is it important to the gameplay and text options what name the player chooses?  Especially if players enter their name digit-by-digit as in my third question, this will cause them to miss portions of the story based on a pretty much random decision.  Without understanding the conext of your story, I'm struggling to understand why name choice should have any effect on gameplay.

Apologies for the unclear feedback.

Advanced Name and Variable

2 years ago
First of all, just saying, I'd really, really recommend just providing a list of names for the player to pick from, that massively simplifies everything and still lets you give custom responses using the normal method with On Page scripting. There is IMO very little value in letting the player write in their own.

Second of all, this would really appear to be a javascript question more than anything to do with the advanced editor. There are very few people who are going to even be able to begin to help you here. @BradinDvorak would be about it, and he may be busy.

Advanced Name and Variable

2 years ago

I agree there is very little value. But the fun in this for me is doing something slightly unique. Hopefully, it pays off. If not, that's okay I learned some new things. 

Also, JavaScript is neat! Sorry if I posted my question in the wrong place, but I am happy nonetheless to have received a supportive answer. Someone needs a medal.

Advanced Name and Variable

2 years ago

With custom names, each letter is stored in its own variable, so for each name you're testing for you'll have to make a long conditional. For "Bob", for instance, the code would look like this:

IF %N0 = 66 AND %N1 = 111 AND %N2 = 98 AND %N3 = 0 THEN %TNAME := 2

Each letter is represented as a number (its UTF-16 codepoint), and this is case sensitive. That fourth check (%N3 = 0) is to make sure it's exactly "Bob" and doesn't just start with "Bob". You can use this CodePen to generate the conditionals quickly.

Advanced Name and Variable

2 years ago
(Note to self: this is why you refresh before posting, especially if there's a lot of time between opening the page and clicking the button).

Just want to add that this is very neat!

Advanced Name and Variable

2 years ago

Amazing! Super helpful! Thanks a ton!

Advanced Name and Variable

2 years ago

I tried to figure it out, but my skill level ain't there.

Depending on how much you understand what you're doing, my suggestion is:

Have a link for every unique name (and one for all other names) that have the same text and lead to the same page. The unique name links will just modify %TNAME in their link scripts.

Then, write a JavaScript function to hide the links depending on the name that the user gave earlier. So, if the name is Alice, the only link that'll be visible is the one corresponding to Alice.

The issue with this approach is that, because you're just making HTML elements not visible, a 'clever' user could easily make the links visible again and click them, breaking your game.

I don't think this is a big deal, since if a user is actively trying to break your game, they can just turn off JavaScript.

Hopefully someone more knowledgeable answers, since it'd be neat to see how they'd go about this. And if someone more knowledgeable happens to be reading this, I've got a question of my own:

If I add the script tags for CDNs to use JQuery, would that work? I'm talking about adding them directly to the CYS page text, since I don't know how (or if you can) add stuff to the head element. I guess I could try doing it, but given my recent experience, I'd probably make some mistake. As such, I'm more curious about it being hypothetically possible, aha.

Advanced Name and Variable

2 years ago

Yes, script tags do not need to be in the document head to work. In fact, it's pretty common to put scripts in the bottom of the body to improve the page load time. You just need to be sure that the script isn't being referenced by anything before it's loaded in.