Jump to content
  • Advertisement
Sign in to follow this  
Pkds7

Data structure for dialoge?

This topic is 1752 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm making a simple game in processing, and I am not sure what type of data structure should hold a Npc's dialoge.

Right now each npc has an array list of strings and the game cycles through them as you talk. I find this annoying because I will have to load the speech data backwards from a file. This method doesn't allow for other scripted actions either. (e.g. giving the player an item)

Is there another data structure that would be better for loading from a file and other stuff?

I'm a novice/ hobbyist programmer. I've heard about stacks, but I don't know much about them.

Thank you in advance!

Share this post


Link to post
Share on other sites
Advertisement
I will have to load the speech data backwards from a file.

 

This seems odd. Could you explain why you have to do this? What happens if you don't?

 

 

Is there another data structure that would be better for loading from a file and other stuff?

 

I don't know about "better for loading from a file," but it seems to me that dialogue would be better modelled as some sort of tree if you want NPCs to say different things depending on the situation, or to (more generally) carry out different actions depending on how the player responds to them. This wiki article may be helpful to you: http://en.wikipedia.org/wiki/Dialog_tree

 

I've heard about stacks, but I don't know much about them.

 

 

A stack is what's known as a "first in, last out" abstract data structure. As you can probably deduce from the name, this means that the first element you put into the stack will be the last one you take out of it. In particular, you may only insert ("push") or remove ("pop") data at the "top" of the stack. As you add elements to the stack, the stack "grows" from the "top" towards the "bottom" of the stack. As you remove elements, the stack "shrinks" from the top towards the bottom. I don't know much about Processing, so I don't know what kind of data structures are built into either it or its standard libraries, but from what I've seen, it does have arrays, so you could implement your own stack on top of those. More information here: http://en.wikipedia.org/wiki/Stack_(abstract_data_type)

 

But again, why do you think you need a stack to handle your dialogue?

Edited by Oberon_Command

Share this post


Link to post
Share on other sites

The program at the end of the array list and cycles towards the first item. I learned that this is the "good" way to use an array list. Is it okay at some times to start from 0 and count upwards?

Share this post


Link to post
Share on other sites

Normally programmers loop an array from 0 to [end index]. Going backwards is usually a special case.

 

I would recommend the book "Data Structures for Game Programmers".

Edited by Alpha_ProgDes

Share this post


Link to post
Share on other sites

The program at the end of the array list and cycles towards the first item. I learned that this is the "good" way to use an array list. Is it okay at some times to start from 0 and count upwards?

 

Yes, it's actually preferred in most cases. Backwards iteration is a micro-optimization that only applies to certain programming languages. I seem to recall that Java is one language where backwards iteration is said to be faster, but I couldn't tell you if that's the case for Processing.

 

My position: use forward iteration until you have a demonstrated need to use backwards iteration. Don't optimize individual lines of code until it works and your profiling tells you that it will be worth it.

Edited by Oberon_Command

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!