(Resolved) Load XML values and add them to a Glabal Variable

Get help using Construct 2

Post » Tue Aug 26, 2014 2:59 pm

Hi there!

I trying to make something very specific.

For example, I have different objects supposed to be stage. Each stage has a unique variable number(1 for stage 1, 2 for stage 2,... ). I also have a xml file that contains multiple value for each stage (its name, the cost of level 1, 2 and 3 (yes, you can upgrade Stage)).

So, I want to load that xml file, then get a value (stage name and/or Level cost) and add to the selected stage all those informations. the name should appear in the Text object and to cost to a global variable.

The problem is that I'm not sure that it's even possible. I think of this method to get all the stages values in a single xml file, so I won't have to change everything in the capx file.

(The capx file I create is attached)

If anyone have a solution for this...
Thanks for your help!
You do not have the required permissions to view the files attached to this post.
Last edited by mardoch on Thu Aug 28, 2014 10:23 am, edited 1 time in total.
B
5
S
1
Posts: 29
Reputation: 433

Post » Tue Aug 26, 2014 3:07 pm

You don't need the extra quotes in the file, just the C2 string.
ImageImageImage
B
71
S
21
G
230
Posts: 3,688
Reputation: 128,847

Post » Tue Aug 26, 2014 3:33 pm

Well, I got a syntax error if I don't put them... How can I put the Xpath without the quotes?
B
5
S
1
Posts: 29
Reputation: 433

Post » Tue Aug 26, 2014 3:39 pm

<?xml version="1.0" ?>

<stages>

<stage>
<ID>1</ID>
<name>The First Stage</name>
<Level1>5</Level1>
<Level2>500</Level2>
<Level3>5000</Level3>
</stage>

<stage>
<ID>2</ID>
<name>The Second Stage</name>
<Level1>6</Level1>
<Level2>600</Level2>
<Level3>6000</Level3>
</stage>

<stage>
<ID>3</ID>
<name>The Third Stage</name>
<Level1>7</Level1>
<Level2>700</Level2>
<Level3>7000</Level3>
</stage>

<stage>
<ID>4</ID>
<name>The Fouth Stage</name>
<Level1>8</Level1>
<Level2>800</Level2>
<Level3>8000</Level3>
</stage>

<stage>
<ID>5</ID>
<name>The Fifth Stage</name>
<Level1>9</Level1>
<Level2>900</Level2>
<Level3>9000</Level3>
</stage>

</stages>
ImageImageImage
B
71
S
21
G
230
Posts: 3,688
Reputation: 128,847

Post » Tue Aug 26, 2014 3:46 pm

Just to clarify further, blackhornet is referring to the quotes around the text within the StageTest.xml file. Just remove the start and end quotes.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
84
Posts: 5,375
Reputation: 58,432

Post » Tue Aug 26, 2014 4:09 pm

Ah ok! Thanks, I get it.
But it doesn't solve my issue in fact. My datas aren't loaded yet.
Is it something in the events I miss?
B
5
S
1
Posts: 29
Reputation: 433

Post » Tue Aug 26, 2014 4:14 pm

You also had double quotes in this string, wrapping the "1.0":

<?xml version="1.0" ?>
If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
84
Posts: 5,375
Reputation: 58,432

Post » Wed Aug 27, 2014 8:03 am

Alright, thank you guys. I change my xml file and now it's properly loaded.
However,I get back now to my main question: can I just load the node that is equal to my global variable (named "Stage") ?
Actually it only load the first node of the xml.
I try different sting value like
Code: Select all
XML.StringValue("/stages/stage[ID='" & Stage & "']/name")
(I get that from another topic) but i fail...
You do not have the required permissions to view the files attached to this post.
B
5
S
1
Posts: 29
Reputation: 433

Post » Wed Aug 27, 2014 9:16 am

mardoch wrote:Alright, thank you guys. I change my xml file and now it's properly loaded.
However,I get back now to my main question: can I just load the node that is equal to my global variable (named "Stage") ?
Actually it only load the first node of the xml.
I try different sting value like
Code: Select all
XML.StringValue("/stages/stage[ID='" & Stage & "']/name")
(I get that from another topic) but i fail...


This should work
Code: Select all
"/stages/stage/ID[contains(text(), '" & stage & "')]/following-sibling::name/text()"

---

If you designed your xml like below might be easier

<stages>
<stage id="1">
<name>The First Stage</name>
<Level1>5</Level1>
<Level2>500</Level2>
<Level3>5000</Level3>
</stage>
</stages>


Code: Select all
"/stages/stage[@id='"&stage&"']/name/text()"
B
32
S
6
G
2
Posts: 317
Reputation: 2,801

Post » Wed Aug 27, 2014 12:00 pm

Still don't work. I designed my xml as you recommended IndieKiwi, but it doesn't change anything :(
B
5
S
1
Posts: 29
Reputation: 433

Next

Return to How do I....?

Who is online

Users browsing this forum: darkrealos, JaredX, Rhindon and 21 guests