How do I do typewriter effect with XML

Get help using Construct 2

Post » Fri Dec 16, 2016 1:19 pm

Hello,

Im using AJAX and XML following this guide: https://www.scirra.com/tutorials/807/ho ... -game-talk

Its working fine but the only problem now is the typewriter effect. Before implementing XML I was using a SourceText object to reference where to get the text from. Now I am not sure what to write to reference the specific line in XML.

So it goes like this:
Every 0.05 seconds --> Set Text: left(SOURCE, len(FinalText.Text) + 1)

I tried using this: xml.StringValue("/chapter1/hint[@id='intro1']/text()") but it doesnt work.

Can someone help me?
Thanks
@coyowl

coyowl.com

Game studio with a portfolio of 3 Apple Featured games.
B
31
S
7
G
2
Posts: 111
Reputation: 2,412

Post » Fri Dec 16, 2016 3:06 pm

Image
B
63
S
23
G
7
Posts: 1,480
Reputation: 10,796

Post » Fri Dec 16, 2016 6:36 pm

Thank you very much for your reply! It works! :)
@coyowl

coyowl.com

Game studio with a portfolio of 3 Apple Featured games.
B
31
S
7
G
2
Posts: 111
Reputation: 2,412

Post » Fri Apr 07, 2017 1:56 am

I was curious if Someone could comment on the Capx or explain what these mean.

1: "Request Dialogue.xml (tag "Dialogue")"
Why does a tag have to be used here? Wouldn't the name of the XML file be enough?

2: "Load XML document from string AJAX.LastData"
Why do I need to use AJAX to load an XML? and what is LastData actually doing?

I looked it up, but don't fully understand it.
"The LastData expression can be used to access the content of the response."

3: Every 1.0/10 Seconds
"left(xml.StringValue("/chapter1/hint[@id="&"'intro"&NumberOfLines&"']/text()"),len(Text.Text)+1)"

I am not fully understanding the
"(/chapter1/hint[@id="&"'intro"&NumberOfLines&"']/text()"),len(Text.Text)+1)"
part, can somebody explain this a bit?

4: Is there a reason to have "Every 1.0/10 Seconds" instead of just having "0.1"?
I sometimes miss simple things. I don't think there is, but I may be missing something.

5: Compare two values

len(Text.Text)
=
len(xml.StringValue("/chapter1/hint[@id="&"'intro"&NumberOfLines&"']/text()"))

I don't understand the 1st value. It is seemingly getting length, but what is (Text.Text) doing?
The 2nd value is the same as in question 3. If question 3 is explained then this would be too.
I know this is getting the current value as well.

Another question. How do I just post the text all at once instead of having a typing effect that is in question 3?
I would like to use the typing effect, but in some spots I need to just have the text appear all at once.

Thanks. I know it may be a bit of a large request. :shock:
It is just if you don't know something or the lingo is a commonly used word, it is sometimes hard to look up.
B
59
S
33
G
13
Posts: 223
Reputation: 12,105

Post » Fri Apr 07, 2017 3:27 am

1. Tags are used to organize and specify in case multiple requests are made. They are not strictly necessary, but it is good practice to use descriptive tags. (If you're only making one request, you don't need tags. If you make a lot of requests, you definitely need them to sort things out)

2. AJAX requests are asynchronous - they are not instantaneous, and there is no way to know when you're going to get the data after you request it. So there is a trigger for AJAX On Completed, where AJAX.lastdata holds whatever information you requested.

Why do you need AJAX? Because the XML plugin has no way of getting the data from a project file - you need AJAX to do so. When you use "Load XML", you're putting the data you retreived from the project file via AJAX into the XML object.

3. This is the typewriter function. This is source, or whole text - xml.StringValue("/chapter1/hint[@id="&"'intro"&NumberOfLines&"']/text()"). len(Text.Text)+1 is how long Text currently is (starts at 0) and adds 1. The left(a,b) expression that wraps the whole thing means take the "b" number of leftmost characters of source "a"

4. Not that I know of.

5. len(Text.Text) How many characters the Text object is currently displaying. len(xml...) is how many characters the source text is. When they equal each other, that means what you are displaying is the entirety of the source text, and therefore there is no need to continue adding one character to display.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Fri Apr 07, 2017 4:36 am

1. I know what tags are called for, I was asking why a tag was needed to request an xml file. I did ask that wrong, sorry.
It won't let me remove the tag on Request Dialogue.xml. I didn't see a reason for that.

Request Dialogue.xml (tag "Dialogue")
Dialogue isn't a tag in Dialogue.xml. The only tags in Dialogue are "chapter1" and "hint". dialogue isn't even an attribute or attribute id.

2. You answered that clearly, thanks.

3. I wasn't familiar with the native expressions:

left(text, count)
Return the first count characters of text.

len(text)
Return the number of characters in text.

I knew this was the typewriter part, I wasn't sure how it was working because of the formula.
Now that I had a while to think about it and you pointed out left had an (a,b), I know most of it now.
+1 makes sense to me now, I was confused by all the new native expressions.

left( xml.StringValue("/chapter1/hint[@id="&"'intro"&NumberOfLines&"']/text()"), len(Text.Text)+1)

I am not understanding
@id= or /text()

4: Thank you

5: I'm not 100% sure how len(Text.Text) is getting the length.
I am now guessing Text.Text is something like Self.Height?
Since it is in the same action it already knows what it is referring to.
I am just not clear on why the same word is repeated twice.



How do I just post the text all at once instead of having a typing effect that is in question 3?
I would guess I could set "Every X Seconds" to 0, but it would seem like it would do more work that way versus just displaying all at once.

Would it be this?
"/chapter1/hint[@id="&"'intro"&NumberOfLines&"']/text()"

I was also curious how to break the line in XML file. is it just by pressing enter or do I have to do something like </br>?
B
59
S
33
G
13
Posts: 223
Reputation: 12,105

Post » Fri Apr 07, 2017 7:59 am

Guys look at Ashleys example with only 1 line of cod its so much easier and it looks better!
Image
B
20
S
10
G
10
Posts: 229
Reputation: 7,624

Post » Sat Apr 08, 2017 6:55 pm

i failed to implement a simple "restart layout" button in the XML2Speach demo. any chance of a simple restart button.
when i try the layout will restart but chapter 2- chapter X will not be displayed and it will show nothing and skips to the "end of demo" display.
B
79
S
28
G
108
Posts: 194
Reputation: 59,906


Return to How do I....?

Who is online

Users browsing this forum: rotacak and 4 guests