Retriving an inventory from WWW?

I been using the WWW.data to get single information from the SQL such as Name, level etc…

But using the echo function on the php it sends out an String.

So i find my self in a problem on how to retrieve an array of items like in an inventory.

Is it posible to do it just via php? or do i need to use any kind of api for that?

Well for instance, World of Warcraft uses item ID’s.

Every inventory slot has a value - either null or an item ID.

Save your item ID’s as strings and save Item data on the server.
Then the player gets all ID’s for each inv slot from the database and via the server the client gets information on items with corresponding IDs.

-Jedy

Just have your server-side PHP use echo to write out a string in a format you’re ready to parse. For example, have it write out a simple XML string, then when you pull that with WWW.data you can parse the string and use the parsed data to build your inventory list. Of course using XML isn’t strictly necessary, it could be that you just write out a comma delimited list then break that up upon retrieval.

But the basic point is this: WWW.data is only ever going to get you a string back from your PHP file, you just need to work that string into your desired format after retrieval, it’s just basic string manipulation work and you can slice it dozens of ways so find one that suits you! :slight_smile:

HiggyB, That was the logic i was doing in my head. But i don’t know how parse work and how to do that when it’s more than one item.

Do you have a link or some reference i can check? or how should i search for it?

Acording to what you say i can convert an String of results into an array? That would be great.

will this be the case? shoud i use .net?

http://articles.techrepublic.com.com/5100-10878_11-6030362.html

Those String methods should all exist in UnityScript as well.

Yes, I have a sample project you can look at for reference, although it pulls a simple XML file and parses that as an array of planets (or bodies), each with its own set of data. It’s an orbital motion simulator with a mini-XML parser I wrote that should serve as an example from which you can build on as it:

  1. Shows how to use the WWW class to pull a file.
  2. How to write a simple parsing routine to read the results and build an array out of them.

First, the project can be seen in action here:

OrbitSim

The source project can be downloaded from here:

OrbitSim Source (1.9MB)

The whole simulation is configured by reading in an external XML file so it’s all data driven. For reference, here is the XML that I read in to the demo above:

<system camdistance="3.0" name="Inner-Planets"> 
  <body name="Sun" mass="1.9891e30.0" radius="0.2" inclination="0.0" color="yellow" semimajoraxis="0.0" avgspeed="0.0"/> 
  <body name="Mercury" mass="3.3022e23.0" radius="0.04" inclination="6.34" color="tan" semimajoraxis="5.7909e10.0" avgspeed="4.787e4.0"/> 
  <body name="Venus" mass="4.8685e24.0" radius="0.12" inclination="2.19" color="orange" semimajoraxis="1.0821e11.0" avgspeed="3.502e4.0"/> 
  <body name="Earth" mass="5.9736e24.0" radius="0.12" inclination="1.5" color="blue" semimajoraxis="1.4960e11.0" avgspeed="2.9783e4.0"/> 
  <body name="Mars" mass="6.4185e23.0" radius="0.08" inclination="1.67" color="red" semimajoraxis="2.2794e11.0" avgspeed="2.4077e4.0"/> 
</system>

Notice that the “system” as a whole has some properties, then it also has a list of “bodies”, and each “body” has its own data associated with it. In your case instead of a system it would be an “inventory” and instead of having barious “bodies” you’d have “items” each of which would have properties (like item type, perhaps a value, etc.).

From there you should be able to sort things out well enough, good luck!

Thx a lot. Very kind of you to help me out. very much apreciated!