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.
playerName = 'Alice' then %TNAME = 1
playerName = 'Bob' then %TNAME = 2
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.
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.
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.
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.
Amazing! Super helpful! Thanks a ton!
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.
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.
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.
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.