Passing a javascript variable to Squiffy
Rockenden
07 May 2015, 15:10Hi,
I want to pass a player name attribute into Squiffy from a javascript prompt. Is this possible?
Here's what I've got so far.
Cheers!![Smile :)](/phpbb-smilies/icon_smile.gif)
I want to pass a player name attribute into Squiffy from a javascript prompt. Is this possible?
Here's what I've got so far.
Cheers!
![Smile :)](/phpbb-smilies/icon_smile.gif)
<form name=myform>
<input type=button value="Enter name"
onClick="
s=prompt('Enter your name','Name');
">
</form>
<BR>
[Click for name]
[Click for name]:
squiffy.set("name", "s");
Hello {name}
blood_exchange
24 May 2015, 09:22It might just be because I'm new to this, but it doesn't seem to work.
![](http://i.imgur.com/bMWtwNX.png)
So up until this part, it seems to work alright. I have the code in there exactly as you typed it, and it runs fine. I click the button, and put Dedray as my example name.
I click Okay, and then "Click for name", and...
![](http://i.imgur.com/UgDX8UP.png)
There's no name. Just the letter s. At the bottom, it seems to think his name is "s".
So, I tried taking out the "s", thinking it might be confusing the code.
![](http://i.imgur.com/ghKaa8h.png)
It doesn't seem to recognize the input at all.
![](http://i.imgur.com/bMWtwNX.png)
So up until this part, it seems to work alright. I have the code in there exactly as you typed it, and it runs fine. I click the button, and put Dedray as my example name.
I click Okay, and then "Click for name", and...
![](http://i.imgur.com/UgDX8UP.png)
There's no name. Just the letter s. At the bottom, it seems to think his name is "s".
So, I tried taking out the "s", thinking it might be confusing the code.
![](http://i.imgur.com/ghKaa8h.png)
It doesn't seem to recognize the input at all.
blood_exchange
24 May 2015, 09:26While you're working on this, I'm also trying to figure out how I could change the text depending on whether the user is male or female (such as male and female pronouns).
I don't want to copy/paste the whole entire thing with the different pronouns just to differentiate between guys and girls, but I also want to make it as personal as I can without forcing the person into a specific role.
I don't want to copy/paste the whole entire thing with the different pronouns just to differentiate between guys and girls, but I also want to make it as personal as I can without forcing the person into a specific role.
Rockenden
29 May 2015, 09:54I've made some progress on this. I just need help concatenating the two variables and displaying in squiffy.
This is what I've got so far.
Any help is very much appreciated....
This is what I've got so far.
Any help is very much appreciated....
<p style="font-size:33px; color:red;"> Character Creation</p>
<hr><br><br><br>
Click the links below to create your character. <br>
[FirstName] <br>
[LastName] <br>
[FullName] <br>
<p></p>
<br>
[FirstName]:
$(document).on("click", "#enter-name", function ()
{
var person1 = prompt("Please enter your name", "");
document.getElementById("name1").innerHTML =
"Your first name is " + person1 + "";
squiffy.set ("globalfirstname", person1());
}
);
<button id="enter-name">Enter First name</button>
<p id="name1"></p>
[LastName]:
$(document).on("click", "#enter-name1", function ()
{
var person2 = prompt("Please enter your name", "");
document.getElementById("name2").innerHTML =
"Your Last name is " + person2 + "";
squiffy.set ("globallastname", person2());
}
);
<button id="enter-name1">Enter Last name</button>
<p id="name2"></p>
[FullName]:
Your Fullname is {globalfirstname + globallastname}.
Alex
29 May 2015, 11:32With a line like this...
You are setting Squiffy's "globalfirstname" attribute to the result of calling a function named person1.
You don't have such a function. You just want the content of the variable named person1, so lose the extra brackets.
squiffy.set ("globalfirstname", person1());
You are setting Squiffy's "globalfirstname" attribute to the result of calling a function named person1.
You don't have such a function. You just want the content of the variable named person1, so lose the extra brackets.
squiffy.set ("globalfirstname", person1);
Alex
29 May 2015, 11:35By the way, are you learning JavaScript while learning Squiffy? If so, that's awesome, but I haven't really designed Squiffy for people who don't know JavaScript. It could be a pretty neat way to learn JavaScript though, so if people are doing that I'll need to keep that in mind when I write more documentation. What other resources are you using?
Rockenden
29 May 2015, 12:00Ahhh, Thank you, Alex.
Can the attributes be seen outside of the section they are defined in. When I click the Fullname link it is still showing as 'null'.
Also can you concatenate variables with a plus sign within the squiffy curly brackets?
ie
[FullName]:
Your Fullname is {globalfirstname + globallastname}.
I did a little bit of java at uni about 8 years ago but don't remember anything at all due to beer :/ I'm using Squiffy not Quest because I wanted to make a gamebook with hyperlinked choices and port it to an app after. I can see the learning curve is quite steep but once I've got the code for the few things I need to do it will just be a matter of amending and cutting and pasting...I hope.
I'm not using any other specific resources. Just googling when I need to do a javascript thing.
Thanks again for the help.
Can the attributes be seen outside of the section they are defined in. When I click the Fullname link it is still showing as 'null'.
Also can you concatenate variables with a plus sign within the squiffy curly brackets?
ie
[FullName]:
Your Fullname is {globalfirstname + globallastname}.
I did a little bit of java at uni about 8 years ago but don't remember anything at all due to beer :/ I'm using Squiffy not Quest because I wanted to make a gamebook with hyperlinked choices and port it to an app after. I can see the learning curve is quite steep but once I've got the code for the few things I need to do it will just be a matter of amending and cutting and pasting...I hope.
I'm not using any other specific resources. Just googling when I need to do a javascript thing.
Thanks again for the help.
Rockenden
29 May 2015, 12:07I've just realised I can just do this:
[FullName]:
Your Fullname is {globalfirstname} {globallastname}.
But can I concatenate the two to become a new attribute?
ie
globalfirstname + globallastname = globalfullname
[FullName]:
Your Fullname is {globalfirstname} {globallastname}.
But can I concatenate the two to become a new attribute?
ie
globalfirstname + globallastname = globalfullname
Alex
29 May 2015, 12:44You can only include one attribute name inside the curly braces. (At the moment anyway - I think Squiffy probably needs proper templating eventually).
So use this:
If you want to concatenate to create a new attribute, use this JavaScript:
(Tip: You can use "get" and "set" instead of "squiffy.get" and "squiffy.set" - they're exactly the same)
So use this:
[FullName]:
Your Fullname is {globalfirstname} {globallastname}.
If you want to concatenate to create a new attribute, use this JavaScript:
set ("globalfullname", get("globalfirstname") + " " + get("globallastname"));
(Tip: You can use "get" and "set" instead of "squiffy.get" and "squiffy.set" - they're exactly the same)
Rockenden
29 May 2015, 16:06blood_exchange wrote:While you're working on this, I'm also trying to figure out how I could change the text depending on whether the user is male or female (such as male and female pronouns).
I don't want to copy/paste the whole entire thing with the different pronouns just to differentiate between guys and girls, but I also want to make it as personal as I can without forcing the person into a specific role.
Hi, Blood exchange.
I'm just learning myself but I've got this in my project which is similar to what you are asking
@title GenderTokenExample
[Select Gender] <br>
[Select Gender]:
Are you [Male] or [Female]?
[Male]:
set("gender", "Male");
set("Boy/Girl", "Boy");
set("boy/girl", "boy");
set("Man/Woman", "Man");
set("man/woman", "man");
set("Sir/madam", "Sir");
set("sir/madam", "sir");
set("Lord/Lady", "Lord");
set("lord/lady", "lord");
set("handsome/pretty", "handsome");
[Continue]
[Female]:
set("gender", "Female");
set("Boy/Girl", "Girl");
set("boy/girl", "girl");
set("Man/Woman", "Woman");
set("man/woman", "woman");
set("Sir/Madam", "Madam");
set("sir/madam", "madam");
set("Lord/Lady", "Lady");
set("lord/lady", "lady");
set("handsome/pretty", "pretty");
[Continue]
[Continue]:
@clear
<IMG SRC="http://i162.photobucket.com/albums/t244/Dimbobx/Dimbobx102/PORTRAIT_Alaree13diana_zpsi0rhvzks.jpg" WIDTH=200 HEIGHT=260>
<br>
<br>
"Ugh! What a hideous looking {man/woman} you are!
"Don't look me in the eye, you bold {boy/girl}!"