XML File not reading

0 favourites
  • 8 posts
From the Asset Store
Convert multiple Excel files into JSON files and import them into construct3.
  • 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:

    XML File:

    <?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>[/code:1jbg5c1q]
    
    Any tips appreciated
  • The header doesn't seem right. Try this one :

    <?xml version="1.0" ?>[/code:2xsgyvl1]
    
    You might even want to specify the file's encoding. If it's UTF-8, go for :
    [code:2xsgyvl1]<?xml version="1.0" encoding="UTF-8"?>[/code:2xsgyvl1]
  • You need a single root element also:

    <?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>
    [/code:1w73j53a]
  • Tried both. No luck. Updated the XML file to:

    <?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>[/code:11syvtxs]
    
    New Event Sheet updated:
    [img="http://www.ascensiongamedev.com/resources/filehost/523d532c9835d47749838ad492913000.png"]
    
    Original thread updated. Thanks for any help in advance
  • You missing the equals-sign:

    <?xml version='1.0'

  • Good spot, But sadly no change. Updated the original thread.

  • Need /data

    This works: xml.StringValue("/data/enemies/enemy/animation")

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you so much

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)