Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Need some help making event editor/Improving my event system

Discussion in 'Scripting' started by Zukas, Jul 31, 2015.

  1. Zukas

    Zukas

    Joined:
    Dec 17, 2013
    Posts:
    40
    Hey! I'm making Event Editor for my game, and I've ran into a problem:

    My events are classes based as nodes, they also have arrays of same type, but different event nodes. This allows me to make branches of nodes. This is how my EventNode class looks like:
    Code (CSharp):
    1. public class EventNode
    2. {
    3.     [XmlAttribute("eventName")]
    4.     public string eventName;
    5.    
    6.     public string eventText;
    7.     public EventOutcome outcome; //Use only in end of branch
    8.  
    9.     public string firstChoiceText;
    10.     public string secondChoiceText;
    11.     public string thirdChoiceText;
    12.     public string fourthChoiceText;
    13.    
    14.     public EventNode[] firstNode;
    15.     public EventNode[] secondNode;
    16.     public EventNode[] thirdNode;
    17.     public EventNode[] fourthNode;
    18. }
    Problem is C# doesn't have reference to variables function. The way I have it right now, is that it loads array I want, and then when I'm happy with it, I apply it, sadly I don't know how to tell code which one array to apply newly made array to. I've tried making insane array trackers with enums to track which array to apply, but it just doesn't seem like right path.

    All tips, suggestions and feedback is much appreciated.
     
  2. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    Your EventNode class has arrays of EventNode objects? I'm sorry, I'm not following at all. You're going to have to be a bit more illustrative in your explanation for what this is for and how it works I think. Use examples.
     
  3. Zukas

    Zukas

    Joined:
    Dec 17, 2013
    Posts:
    40
    Sorry, wrote this before going off to sleep at 4AM in local time. xD

    This is how my events look in XML hand made:
    Code (CSharp):
    1. <EventNode eventName="Insane Wanderer">
    2.         <eventText>In distance you noticed a rolling human figure on ground, rolling back and forth.</eventText>
    3.      
    4.         <firstChoiceText>Try to communicate.</firstChoiceText>
    5.         <firstNode>
    6.        
    7.             <EventNode>
    8.                 <eventText>You come somewhat closer and then attempt to communicate with it, however, instead of of replying, the figure stands up and starts walking to you with mad eyes.</eventText>
    9.                
    10.                 <firstChoiceText>Fight it.</firstChoiceText>
    11.                 <firstNode>
    12.                     <EventNode>
    13.                         <eventText>You get into battle stance, ready to fight it.</eventText>
    14.                         <outcome>
    15.                          
    16.                         </outcome>
    17.                     </EventNode>
    18.                     <EventNode>
    19.                         <eventText>You get into battle stance, as soon as it notices your willingness to fight figure starts running away from you at full speed.</eventText>
    20.                         <outcome>
    21.                          
    22.                         </outcome>
    23.                     </EventNode>
    24.                 </firstNode>
    25.                
    26.                 <secondChoiceText>Run away!</secondChoiceText>
    27.                 <secondNode>
    28.                     <EventNode>
    29.                         <eventText>You successfully run away, hell knows what it could have done to you...</eventText>
    30.                         <outcome>
    31.                          
    32.                         </outcome>
    33.                     </EventNode>
    34.                     <EventNode>
    35.                         <eventText>You turn around in order to run away, yet you trip on the very first rock to get in your way. The figure catches up with you, the fight is inevitable.</eventText>
    36.                         <outcome>
    37.                          
    38.                         </outcome>
    39.                     </EventNode>
    40.                 </secondNode>
    41.             </EventNode>
    42.            
    43.             <EventNode>
    44.                 <eventText>Right after it hears your noise, figure's face looks over at you. It's eyes explode and thus he shouts
    45.                 -IT'S YOU, NO! STAY AWAY!
    46.                Right after the words, figure draws out the pistol and releases bullet into it's head.</eventText>
    47.                 <outcome>
    48.                  
    49.                 </outcome>
    50.             </EventNode>
    51.        
    52.         </firstNode>
    53.        
    54.         <secondChoiceText>Try to go around the body without alerting it.</secondChoiceText>
    55.         <secondNode>
    56.             <EventNode>
    57.                 <eventText>You move past the body without catching it's attention.</eventText>
    58.                <outcome>
    59.                
    60.                </outcome>
    61.            </EventNode>
    62.        </secondNode>
    63.    
    64.    </EventNode>
    You can see that in array <firstNode> we have more or just one. <EventNode>. This gets easily confusing when working in Notepad++, and I wanted to make an editor for that. The problem I'm running into, is that I don't know how to keep track of which <firstNode>/<secondNoce>/<thirdNode>/<fourthNode> I'm editing at the moment inside editor. It branches out as I can go to <thirdNode> array, I choose an <EventNode> inside of that array and finally in it I can choose <firstNode> array.

    I'm just looking on how to keep track on which array I'm working on currently or completely other structure I could try work with.
     
  4. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    I made a program in Visual Studio awhile back that handled story event management. Eventually the data got dumped out to XML, and the results (this is one of the more simple examples) looked more like:



    Of course, that was meant to handle events in a very different way, but my point remains. There's a limit to how far you can go when hand-editing XML files. Your events need branching data, ID numbers, the ability to hold context-specific instructions like markers for skipping a section if some variable is false or w/e. You need to get a better method to put data into the XML file (I built my own, but it took several months- you can just use any real XML editor).

    Anyways, IMO your events should only have a single array, and how the specific nodes within that array are processed should really be what you're focusing on. You could do it the PyGame way and use the equivalent of "GoTo" to just skip past any nodes that aren't necessary (like choosing option B simply skips past everything until it reaches the "B" marker with the same event ID, or something). That way you can load the entire thing sequentially, process it sequentially, and not get caught up on whether something is 3 nodes deep or 4 or whatever.

    You really do need to use a real XML editor though...
     
  5. Zukas

    Zukas

    Joined:
    Dec 17, 2013
    Posts:
    40
    Thanks for input, I guess it's time to re-structurize my event system as it's really becoming a hassle. Are there any XML editors you can recommend? Free preferably, but if it's truly good, paid one is fine as well.
     
  6. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    XML Copy Editor probably, because it's simple. The CAM/CAMV XML Editor is fantastic, but it has too many features that sort of get in the way of everyday use.

    You could also volunteer to test the one I made awhile back expressly for this purpose- it has the source files included and everything (VS2013), but it's not an XML editor exactly... *shrugs* It also had about zero marketability, so I haven't really done anything with it. You can find on my website store for free, if you like, just be sure to grab the full one and not the demo.
     
  7. Zukas

    Zukas

    Joined:
    Dec 17, 2013
    Posts:
    40
    I'll check both XML Copy Editor and your made program, might come in use for other stuff aswell. Thanks! :D