XML File not reading

Get help using Construct 2

Post » Fri Jun 09, 2017 5:13 pm

Hi, for my game i plan to load certain data for enemies randomly for different levels from an XML file. I'm unable to get the XML file to read and write the results in a test textbox. Can anyone explain what i'm doing wrong?

Event Sheet:
Image

XML File:
Code: Select all
<?xml version='1.0' encoding="UTF-8"?>
<data>
   <enemies>
      <enemy id='1'>
         <animation>cat</animation>
         <health>2</health>
         <jumping>false</jumping>
         <targetplayer>false</targetplayer>
         <speed>150</speed>
         <jump>600</jump>
      </enemy>
      <enemy id='2'>
         <animation>bat</animation>
         <health>1</health>
         <jumping>true</jumping>
         <targetplayer>true</targetplayer>
         <speed>250</speed>
         <jump>600</jump>
      </enemy>
   </enemies>
   <levels>
      <level id='1'>
         <enemy id='1'>1</enemy>
      </level>
      <level id='2'>
         <enemy id='1'>2</enemy>
         <enemy id='2'>1</enemy>
      </level>
   </levels>
</data>


Any tips appreciated :D I've been trying to follow guides on reading XML files however no luck :(
Last edited by Jerrard on Fri Jun 09, 2017 7:19 pm, edited 2 times in total.
B
5
S
1
Posts: 13
Reputation: 351

Post » Fri Jun 09, 2017 6:05 pm

The header doesn't seem right. Try this one :
Code: Select all
<?xml version="1.0" ?>


You might even want to specify the file's encoding. If it's UTF-8, go for :
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
B
74
S
31
G
26
Posts: 994
Reputation: 20,198

Post » Fri Jun 09, 2017 6:46 pm

You need a single root element also:

Code: Select all
<?xml version='1.0' ?>
<data>
<enemies>
   <enemy id='1'>
      <animation>cat</animation>
      <health>2</health>
      <jumping>false</jumping>
      <targetplayer>false</targetplayer>
      <speed>150</speed>
      <jump>600</jump>
   </enemy>
   <enemy id='2'>
      <animation>bat</animation>
      <health>1</health>
      <jumping>true</jumping>
      <targetplayer>true</targetplayer>
      <speed>250</speed>
      <jump>600</jump>
   </enemy>
</enemies>
<levels>
   <level id='1'>
      <enemy id='1'>1</enemy>
   </level>
   <level id='2'>
      <enemy id='1'>2</enemy>
      <enemy id='2'>1</enemy>
   </level>
</levels>
</data>
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Fri Jun 09, 2017 7:12 pm

Tried both. No luck. Updated the XML file to:

Code: Select all
<?xml version='1.0' encoding="UTF-8"?>
<data>
   <enemies>
      <enemy id='1'>
         <animation>cat</animation>
         <health>2</health>
         <jumping>false</jumping>
         <targetplayer>false</targetplayer>
         <speed>150</speed>
         <jump>600</jump>
      </enemy>
      <enemy id='2'>
         <animation>bat</animation>
         <health>1</health>
         <jumping>true</jumping>
         <targetplayer>true</targetplayer>
         <speed>250</speed>
         <jump>600</jump>
      </enemy>
   </enemies>
   <levels>
      <level id='1'>
         <enemy id='1'>1</enemy>
      </level>
      <level id='2'>
         <enemy id='1'>2</enemy>
         <enemy id='2'>1</enemy>
      </level>
   </levels>
</data>


New Event Sheet updated:
Image

Original thread updated. Thanks for any help in advance :D
Last edited by Jerrard on Fri Jun 09, 2017 7:19 pm, edited 1 time in total.
B
5
S
1
Posts: 13
Reputation: 351

Post » Fri Jun 09, 2017 7:13 pm

You missing the equals-sign:
<?xml version='1.0'
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Fri Jun 09, 2017 7:18 pm

Good spot, But sadly no change. Updated the original thread.
B
5
S
1
Posts: 13
Reputation: 351

Post » Fri Jun 09, 2017 7:34 pm

Need /data

This works: xml.StringValue("/data/enemies/enemy[@id=1]/animation")
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Fri Jun 09, 2017 7:37 pm

Thank you so much :D
B
5
S
1
Posts: 13
Reputation: 351


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 37 guests