Load values from a document

Get help using Construct 2

Post » Mon May 27, 2013 12:48 pm

I am making a game which (in short) is an array of quests, in random order.

When the quest_button is clicked on, I want to load a random quest. Now, the randomization is not the issue here.

I thought about using XML:
[code]
<?xml version="1.0" encoding="utf-8"?>
<Title>Some Quest</Title>
<Morale>1</Morale>
<Strength>2</Strength>
<Agility>3</Agility>
<Speed>4</Speed>
[/code]

I can load the file using XML's load function, but how do I access the values? EG: How do I set a global variable named current_speed to the speed defined in the XML file, in this case 4.

Of course, I do not have to stick to XML so if any of you know how to do this either with or without XML, please do help me out on this one.
B
3
Posts: 4
Reputation: 183

Post » Mon May 27, 2013 12:58 pm

https://www.scirra.com/tutorials/354/xml-parsing

JSON works too if you are more into that kind of thing.
B
24
S
9
G
7
Posts: 756
Reputation: 7,302

Post » Mon May 27, 2013 1:27 pm

Usage:

XML content:
[code]<?xml version="1.0" encoding="utf-8"?>
<Voyage>
     <Specification title="Save The Princess" morale="1" strength="2" agility="3" speed="4"></Specification>
</Voyage>[/code]

voyage_widget is a sprite I use as button; when it is clicked I want it to load the XML file.

Now, if I just pass on the actual content of the XML file in the XML.load function, Text.setText is correctly setting the title of the textfield to "Save The Princess".

However, trying to load from file simply fails on me.

Thanks for that link by the way, I have figured out the parsing... now it's just the loading :(
B
3
Posts: 4
Reputation: 183

Post » Mon May 27, 2013 1:34 pm

From: https://www.scirra.com/manual/107/ajax

"Also, when previewing in Construct 2 the game runs on localhost. This counts as a different domain to the rest of the internet, so typically AJAX requests to any web page will fail during preview, unless the server explicitly allows cross-domain requests."

I'll upload the exported file and see if it works, then.
B
3
Posts: 4
Reputation: 183


Return to How do I....?

Who is online

Users browsing this forum: FabianB and 42 guests