playMaker

Author Topic: xQueryResult String trimming  (Read 478 times)

GMPlay

  • Playmaker Newbie
  • *
  • Posts: 28
xQueryResult String trimming
« on: October 07, 2022, 01:31:56 PM »
Hi,

I am working on a text system that will use an xml file to extract text as needed.

I have formatted the xml file in the following manner:

<tmnt>

    <turtle id='1'>
        <name>leo</name>
        <color>blue</color>
        <weapon>dualKatana</weapon>
    </turtle>

<turtle id='2'>
        <name>raph</name>
        <color>red</color>
        <weapon>saiBlades</weapon>
    </turtle>

<turtle id='3'>
        <name>mike</name>
        <color>yellow</color>
        <weapon>nunchuks</weapon>
    </turtle>

<turtle id='4'>
        <name>don</name>
        <color>purple</color>
        <weapon>boStaff</weapon>
    </turtle>

</tmnt>

Using xml actions in Datamaker for Playmaker I have managed to come up with an xPath query such that I want the pure String as the final result.

So I am using this query
//turtle [@id='2']/weapon/text()

without any errors I am getting the result
<result>saiBlades</result>

Which is correct. But the issue is that I am getting this along with the tags in the beginning and end which is <result>  and </result>

So I decided to use some kind of trim tools for strings.

I tried some actions such as 'String Trim' and 'String Split'. Tried some combinations, but I am not able to figure out how to trim out the tags.

Any ideas how to get the final string 'saiBlades' without the tags ?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: xQueryResult String trimming
« Reply #1 on: October 11, 2022, 03:16:07 PM »
Hi,
If you have a little coding experience i would strongly consider to use scriptable objects and make some custom actions to get data from it.

xml is very slow.

In our game i had to convert the data to hash tables on start or during loading so that i could access it during gameplay.

Later i found out that scriptables where way better to use and i reworked the game to work with scriptable objects.

i think you need to use 'Select Single Node' action and get the weapon as a property.

so query should be something like : //turtle [@id='2'] (not sure if this is correct)

GMPlay

  • Playmaker Newbie
  • *
  • Posts: 28
Re: xQueryResult String trimming
« Reply #2 on: October 17, 2022, 12:52:29 PM »
Yep, You are right.

'Select Single Node' worked correctly and I am now getting output without those tags.

Good suggestions though on using scriptable objects. The thing is, my overall requirement is very simple. I am fetching simple dialog strings when the player taps on an object - in a point and click adventure game. So nothing crazy like RPG and no complex dialog chains.

So I'd like to keep approach simple as well. An item contains a unique ID and I simply use that ID to seek in the xml to display the correct dialog. Works so far.

However, you have informed that xml is slow, I will have to keep this in check when the xml size gets bigger and especially on mobile. If it is within acceptable range I'll stick to this system else-

Scriptable objects is inevitable for me to use at some point and I will keep this in mind if I see my current approach to be 'limited' and need to add more features.

For now it seems to be sufficient for a quick prototype.

BTW, I loved your XML tutorial on YouTube! With it's help, I was able to make this simple text system for now.

Right now I am using text asset mode.
For localization, I do plan to keep each language version as a separate xml file. Would you please suggest if using xml proxy would be faster, slower performance-wise? and what even is 'in-memory' option?

Thanks as always.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: xQueryResult String trimming
« Reply #3 on: October 18, 2022, 10:18:23 AM »
Hi.
I havent used xml for a while now, i don't know if in memory would be faster (i don't believe so)

in our game i noticed the lag when getting data for (for example) weapons.
when player move to another object it took several frames to update, which was not acceptable
so on that point i started to convert the xml's into hash tabel. (@start of the game)
Then later i found out about scriptables and started to replace xml/hashtables with those(also language i handle with it).

For a quiz game for example, it would be fine as you wont notice it.
for text based game it would probably be fine as well.

GMPlay

  • Playmaker Newbie
  • *
  • Posts: 28
Re: xQueryResult String trimming
« Reply #4 on: October 18, 2022, 01:29:36 PM »
I have to agree with you on that, for a quiz game it is fine.

So now after using it for a while I have come to conclusion that even for a point and click adventure this is fine as well. Due to the fact that the text bubble will only render when player has interacted with an object. This is very much like in a quiz situation.

But then again, I will have to see how it performs later when I fill xml with more content.

Thanks again for your valuable input  :)