[Tutorial]A dialog box system using XML

Get help using Construct 2

Post » Sat Apr 02, 2016 11:12 pm

@kyatric Is there a reason you used 'ids' instead of using node index?

All of the XML tutorials I have seen set ids to numbers which is exactly the same as using the node index but makes it completely barbaric when you want to insert a line somewhere (have to update the id numbers after each change).

Is there a reason for choosing this way? If you are not aware of what I am referring to I can provide an example.
ImageImageImage
B
43
S
26
G
11
Posts: 516
Reputation: 10,473

Post » Sun Apr 03, 2016 2:13 am

@badmoodtaylor: I'm not sure what you are talking about (as OP posting date shows, the tutorial is almost a year old now).
Also, as usual with my tutorials they are examples of implementation only, not absolute truths.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
293
S
117
G
96
Posts: 7,310
Reputation: 71,069

Post » Sun Apr 03, 2016 3:06 am

Kyatric wrote:@badmoodtaylor: I'm not sure what you are talking about (as OP posting date shows, the tutorial is almost a year old now).
Also, as usual with my tutorials they are examples of implementation only, not absolute truths.


I know it is a year old but you just fed me a link to it. I'm not trying to be critical—I just feel like the way I mentioned is more efficient and I don't see tutorials use it...
ImageImageImage
B
43
S
26
G
11
Posts: 516
Reputation: 10,473

Post » Sun Apr 03, 2016 3:55 pm

@badmoodtaylor: Possibly a lack of knowledge in XML.
Again, I'm not completely sure what "node index" is supposed to be and how it works better in this case.
From my quick research, in XPATH it will mostly be used to know the position of a node, which in the end, I'm not sure how is so different then setting IDs to situate it.

If you have a concrete example I'll be glad to have a look at it.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
293
S
117
G
96
Posts: 7,310
Reputation: 71,069

Post » Sun Apr 03, 2016 10:25 pm

@kyatric: I'm not sure what it is called exactly but node index seemed logical. Example:
/bookstore/book[1] Selects the first book element that is the child of the bookstore element.

For some of the examples I have seen it won't be different at all than using IDs but it can save a lot of work in some cases. A lot of times I have used xml has been for dialogue and intro/story where it is subject to a lot of change but I never have to change any id numbers or anything.

The reason why I am asking is that not too long ago I knew nothing about xml. So I want to keep learning and figure out if there are better ways. Also, haven't done one before but was thinking about writing a tutorial on it.

If you want to see some capx: (sorry, they aren't examples, just things I have worked on before, so lots of other stuff in them)

Chooses random node (between 1 and node count):
viewtopic.php?f=148&t=170355

First time using XML, simply changes text every couple of seconds to the next line. Once at end (variable > nodeCount) starts over. I bookmarked the event:
https://www.dropbox.com/s/fvytszs9v3bup ... .capx?dl=0

Something I'm working on now, bookmarked a couple of events. Can talk to people and just got it working where npc can ask you a question and have a response for each answer:
https://www.dropbox.com/s/eschjyoosogyc ... .capx?dl=0

Take a look at the XML sheets in some of these. The Construct events probably won't vary much from your examples but the XML is more straightforward and easier to read. I was looking at your examples and was having a hard time following the XML. Your way works, so there is nothing wrong with it, and it probably helps other people so great, but I didn't want to change my whole system so figured out how to work it with what I had already.

Let me know what you think. That is why I am asking, not to be critical but to get your insight.

Thanks
ImageImageImage
B
43
S
26
G
11
Posts: 516
Reputation: 10,473

Post » Mon Apr 04, 2016 3:42 pm

@badmoodtaylor

The reason to use IDs is to uniquely identify each of the dialogue. So if you want a particular dialogue, you can retrieve it using its ID, whatever its index is in the parent node, and wherever it is in the document.

You should always prioritize the use of attributes to distinguish nodes instead of using different tag names. The structure of your XML document will be much more robust and easier to navigate through.
B
74
S
31
G
25
Posts: 993
Reputation: 19,696

Post » Mon Apr 04, 2016 4:35 pm

@badmoodtaylor

I mostly used the XML structure in the same way we can do picking in Construct 2.
So in the end, in my tutorial, you are picking a dialog/answer/whatever through certain conditions (their attributes) in the same way you pick instances (through their instance variables).
It may be kind of tedious for the organization, but it made sense to me as I was going along, and especially when I needed to link the logic of my XML to my display engine in the tutorial.

To be fair I'm not super familiar with XML either, and I'm afraid there is not much more I can tell about the "best usage practice" of it.
Again, for this tutorial that's what felt natural as I was going along, and still "readable" (allowing me to tie the logic of display/organisation to my code) nonetheless.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
293
S
117
G
96
Posts: 7,310
Reputation: 71,069

Post » Mon Apr 04, 2016 6:24 pm

Magistross wrote:@badmoodtaylor

The reason to use IDs is to uniquely identify each of the dialogue. So if you want a particular dialogue, you can retrieve it using its ID, whatever its index is in the parent node, and wherever it is in the document.

You should always prioritize the use of attributes to distinguish nodes instead of using different tag names. The structure of your XML document will be much more robust and easier to navigate through.


The tutorials I have seen on here have simply used IDs to number each node, id=1, id=2, Id=3, etc this could be replaced by tag[1].

I will keep in mind to try and make use of attribute tags though.
ImageImageImage
B
43
S
26
G
11
Posts: 516
Reputation: 10,473

Post » Mon Apr 04, 2016 8:52 pm

@badmoodtaylor Attributes can be anything you want, I guess tutorials used "id" because it's short and is usually quite self-explanatory. The values could have been something else though, and maybe more verbose to include a bit of metadata (i.e <npc id="Guard1_Town1">...</npc>).
B
74
S
31
G
25
Posts: 993
Reputation: 19,696

Post » Mon Apr 04, 2016 11:34 pm

@magistross It's not that I don't understand how to use them, I am just trying to figure out which method is efficient in different situations. I am still not sure how I can make use of IDs if they are unique, but I can see how attributes can be used effectively—something like this:
Guard1 NormalMessage
Guard1 SpecialMessage
Guard2 NormalMessage
Guard2 SpecialMessage

So you can search for multiple attributes to narrow down the result?

I guess if using nested tags is similar to using folders then using attributes and ids is similar to a search function?
ImageImageImage
B
43
S
26
G
11
Posts: 516
Reputation: 10,473

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests