Thread: [Ruse/Any] Dialogue System - Kotlin/Java | Intelligent Message Splitting Included

Page 4 of 5 FirstFirst ... 2345 LastLast
Results 31 to 40 of 45
  1. #31  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Quote Originally Posted by arham 4 View Post
    Why talk so pretentiously? Just make points to perhaps educate.
    It's fine, he's correct. My "explanation" of it was way off, I started to think about the consequences of it and what's better in the end rather than what actually defines it.

    Quote Originally Posted by Faris View Post
    Do you know what hard-coding is?
    I do, however this dialogue system, with a few minor modifications could be considered non-hardcoded. You could treat the dialogues as plugins, after which the dialogues are no longer considered hard-coded, as you can freely hotswap them during runtime however you wish. If this is not your definition of hardcoding, let me know.

    However all this is besides the point, whether you "hardcode" it or load externally(or through reflection..) plays little to no role in it. What matters is actually writing the dialogues. When it comes to something as heavily referenced as dialogues, you might want to use the best options available to you, which give you the most freedom and force you to write the least amount of code. What Arham has written there fulfills both of these specifications in my book, in fact it's about as decent as a dialogue system can go in pure java. With kotlin, you could definitely play a little more with the boundaries. Writing a dialogue in json however would be a massive pain in the ass. Writing anything in json is a massive pain to begin with.

    I'd like you to explain why you think writing dialogues in json is better than as scripts though(which this basically is).
    Attached image
    Reply With Quote  
     

  2. Thankful user:


  3. #32  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Good job on this, and great contribution. With that being said, what kind of worries me about this design is that it is possible for dialogue to become corrupt. Because a group of Dialogue objects aren't linked together, it's possible for other dialogue to make their way into the queue. Although this is convenient, it's definitely not safe. A better approach would be to think of dialogue as links in a chain, ensuring that other links can't exist in your chain. I took this approach in java so here it is, just food for thought;

    Code:
    DialogueChain first = new DialogueChain().player(FacialAnimation.DEFAULT, "foo");
    
    DialogueChain second = new DialogueChain()
        .player(FacialAnimation.DEFAULT, "foo")
        .player(FacialAnimation.DEFAULT, "foo", "bar")
        .option((p, option) -> {
            if (option == 1) {
                player.setDialogueChain(first).start(player);
            } else {
                player.getPA().closeInterfaces(true);
            }
        }, "title", "first", "second");
    As you can see the first portion of dialogue would never interrupt or corrupt the second portion of dialogue, it's just not possible. This is definitely a more defensive approach and a bit more costly.
    Reply With Quote  
     

  4. Thankful user:


  5. #33  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    23
    Posts
    3,415
    Thanks given
    7,254
    Thanks received
    1,938
    Rep Power
    3905
    Quote Originally Posted by Kris View Post
    It's fine, he's correct. My "explanation" of it was way off, I started to think about the consequences of it and what's better in the end rather than what actually defines it.



    I do, however this dialogue system, with a few minor modifications could be considered non-hardcoded. You could treat the dialogues as plugins, after which the dialogues are no longer considered hard-coded, as you can freely hotswap them during runtime however you wish. If this is not your definition of hardcoding, let me know.

    However all this is besides the point, whether you "hardcode" it or load externally(or through reflection..) plays little to no role in it. What matters is actually writing the dialogues. When it comes to something as heavily referenced as dialogues, you might want to use the best options available to you, which give you the most freedom and force you to write the least amount of code. What Arham has written there fulfills both of these specifications in my book, in fact it's about as decent as a dialogue system can go in pure java. With kotlin, you could definitely play a little more with the boundaries. Writing a dialogue in json however would be a massive pain in the ass. Writing anything in json is a massive pain to begin with.

    I'd like you to explain why you think writing dialogues in json is better than as scripts though(which this basically is).
    Oh, I was unaware that he meant hardcoded in the sense of reloadability.



    Quote Originally Posted by Jason View Post
    Good job on this, and great contribution. With that being said, what kind of worries me about this design is that it is possible for dialogue to become corrupt. Because a group of Dialogue objects aren't linked together, it's possible for other dialogue to make their way into the queue. Although this is convenient, it's definitely not safe. A better approach would be to think of dialogue as links in a chain, ensuring that other links can't exist in your chain. I took this approach in java so here it is, just food for thought;

    Code:
    DialogueChain first = new DialogueChain().player(FacialAnimation.DEFAULT, "foo");
    
    DialogueChain second = new DialogueChain()
        .player(FacialAnimation.DEFAULT, "foo")
        .player(FacialAnimation.DEFAULT, "foo", "bar")
        .option((p, option) -> {
            if (option == 1) {
                player.setDialogueChain(first).start(player);
            } else {
                player.getPA().closeInterfaces(true);
            }
        }, "title", "first", "second");
    As you can see the first portion of dialogue would never interrupt or corrupt the second portion of dialogue, it's just not possible. This is definitely a more defensive approach and a bit more costly.
    I see your point. I believe the problem you stated actually may have caused me some conflict at times. However, shouldn't dialogues not be so closely linked? Because then, what happens when dialogues wish to reference backwards? That's a problem I face in my system too. I was advised by somebody to instead use a hashmap and allow the helper methods to redirect the next dialogue to a previous (or another) key.

    I appreciate the feedback.
    Attached image
    Attached image
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work here!
    Reply With Quote  
     

  6. Thankful user:


  7. #34  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Quote Originally Posted by arham 4 View Post
    Oh, I was unaware that he meant hardcoded in the sense of reloadability.




    I see your point. I believe the problem you stated actually may have caused me some conflict at times. However, shouldn't dialogues not be so closely linked? Because then, what happens when dialogues wish to reference backwards? That's a problem I face in my system too. I was advised by somebody to instead use a hashmap and allow the helper methods to redirect the next dialogue to a previous (or another) key.

    I appreciate the feedback.
    Yeah I could definitely see how it would cause issues. I see no issue with linking them, and in the point above I showed just how it would be possible to link 2 chains together. It doesn't make much sense to use a Map when order is necessary. Instead, you could use a list and maintain the index of the current link in the chain, like in the example below. In this class you can traverse and go to the previous link, forward to the next link, you can obtain the current link, etcetera. It allows you to do quite a bit. Simply calling #start would allow you to reset back to the first link.

    Code:
    public class DialogueChain {
    
    
    	private final List<DialogueLink> links = new ArrayList<>();
    
    
    	private int indexOfLink;
    
    
    	public void start(Player player) {
    		indexOfLink = 0;
    		show(player);
    	}
    
    
    	public void next(Player player) {
    		DialogueLink link = links.get(indexOfLink);
    
    
    		if (link != null) {
    			link.getContinueListeners().forEach(listener -> listener.onContinue(player, link.getDialogue()));
    		}
    		indexOfLink++;
    		show(player);
    	}
    
    
    	public boolean isOnLastLink() {
    		return indexOfLink == links.size() - 1;
    	}
    
    
    	public void end(Player player) {
    		DialogueLink link = links.get(indexOfLink);
    
    
    		if (link != null) {
    			link.getCloseListeners().forEach(listener -> listener.onClose(player, link.getDialogue()));
    		}
    		indexOfLink = 0;
    	}
    
    
    	public void previous(Player player) {
    		indexOfLink--;
    
    
    		if (indexOfLink < 0) {
    			indexOfLink = 0;
    		}
    		show(player);
    	}
    
    
    	public void show(Player player) {
    		DialogueLink link = links.get(indexOfLink);
    
    
    		if (link == null) {
    			return;
    		}
    		link.execute(player);
    	}
    
    
    	public DialogueChain link(DialogueLink link) {
    		links.add(link);
    
    
    		return this;
    	}
    
    
    	public DialogueLink getCurrentLink() {
    		return links.get(indexOfLink);
    	}
    
    
    	public DialogueChain option(ClickOptionDialogueListener optionListener, String title, String... options) {
    		if (options == null || options.length < 2 || options.length > 5) {
    			throw new IllegalArgumentException("Length of options must be between 2 and 5 inclusive and cannot be null.");
    		}
    		if (optionListener == null) {
    			throw new IllegalArgumentException("Option listener cannot be null.");
    		}
    		links.add(new DialogueLink(new OptionDialogue(title, options)).addClickOptionListener(optionListener));
    
    
    		return this;
    	}
    
    
    	public DialogueChain player(FacialAnimation animation, String... message) {
    		if (animation == null) {
    			throw new IllegalArgumentException("Animation for players face cannot be null.");
    		}
    		if (message == null || message.length == 0) {
    			throw new IllegalArgumentException("Messages length cannot be null and must be greater than zero.");
    		}
    		links.add(new DialogueLink(new PlayerDialogue(animation, message)));
    
    
    		return this;
    	}
    
    
    	public DialogueChain npc(NpcDefinition definition, FacialAnimation animation, String... message) {
    		if (definition == null || definition.name == null) {
    			throw new IllegalArgumentException("Definition or definition name is null, not permitted.");
    		}
    		if (animation == null) {
    			throw new IllegalArgumentException("Animation for npc cannot be null.");
    		}
    		if (message == null || message.length < 1 || message.length > 4) {
    			throw new IllegalArgumentException("Amount of lines must be between 1 and 4 inclusive. ");
    		}
    		links.add(new DialogueLink(new NpcDialogue(definition, animation, message)));
    
    
    		return this;
    	}
    
    
    	public DialogueChain statement(String... messages) {
    		if (messages == null || messages.length == 0 || messages.length > 6) {
    			throw new IllegalArgumentException("Messages cannot be null and must contain between 1 and 5 elements.");
    		}
    		links.add(new DialogueLink(new StatementDialogue(messages)));
    
    
    		return this;
    	}
    Reply With Quote  
     

  8. Thankful user:


  9. #35  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    23
    Posts
    3,415
    Thanks given
    7,254
    Thanks received
    1,938
    Rep Power
    3905
    Quote Originally Posted by Jason View Post
    Yeah I could definitely see how it would cause issues. I see no issue with linking them, and in the point above I showed just how it would be possible to link 2 chains together. It doesn't make much sense to use a Map when order is necessary. Instead, you could use a list and maintain the index of the current link in the chain, like in the example below. In this class you can traverse and go to the previous link, forward to the next link, you can obtain the current link, etcetera. It allows you to do quite a bit. Simply calling #start would allow you to reset back to the first link.

    Code:
    public class DialogueChain {
    
    
    	private final List<DialogueLink> links = new ArrayList<>();
    
    
    	private int indexOfLink;
    
    
    	public void start(Player player) {
    		indexOfLink = 0;
    		show(player);
    	}
    
    
    	public void next(Player player) {
    		DialogueLink link = links.get(indexOfLink);
    
    
    		if (link != null) {
    			link.getContinueListeners().forEach(listener -> listener.onContinue(player, link.getDialogue()));
    		}
    		indexOfLink++;
    		show(player);
    	}
    
    
    	public boolean isOnLastLink() {
    		return indexOfLink == links.size() - 1;
    	}
    
    
    	public void end(Player player) {
    		DialogueLink link = links.get(indexOfLink);
    
    
    		if (link != null) {
    			link.getCloseListeners().forEach(listener -> listener.onClose(player, link.getDialogue()));
    		}
    		indexOfLink = 0;
    	}
    
    
    	public void previous(Player player) {
    		indexOfLink--;
    
    
    		if (indexOfLink < 0) {
    			indexOfLink = 0;
    		}
    		show(player);
    	}
    
    
    	public void show(Player player) {
    		DialogueLink link = links.get(indexOfLink);
    
    
    		if (link == null) {
    			return;
    		}
    		link.execute(player);
    	}
    
    
    	public DialogueChain link(DialogueLink link) {
    		links.add(link);
    
    
    		return this;
    	}
    
    
    	public DialogueLink getCurrentLink() {
    		return links.get(indexOfLink);
    	}
    
    
    	public DialogueChain option(ClickOptionDialogueListener optionListener, String title, String... options) {
    		if (options == null || options.length < 2 || options.length > 5) {
    			throw new IllegalArgumentException("Length of options must be between 2 and 5 inclusive and cannot be null.");
    		}
    		if (optionListener == null) {
    			throw new IllegalArgumentException("Option listener cannot be null.");
    		}
    		links.add(new DialogueLink(new OptionDialogue(title, options)).addClickOptionListener(optionListener));
    
    
    		return this;
    	}
    
    
    	public DialogueChain player(FacialAnimation animation, String... message) {
    		if (animation == null) {
    			throw new IllegalArgumentException("Animation for players face cannot be null.");
    		}
    		if (message == null || message.length == 0) {
    			throw new IllegalArgumentException("Messages length cannot be null and must be greater than zero.");
    		}
    		links.add(new DialogueLink(new PlayerDialogue(animation, message)));
    
    
    		return this;
    	}
    
    
    	public DialogueChain npc(NpcDefinition definition, FacialAnimation animation, String... message) {
    		if (definition == null || definition.name == null) {
    			throw new IllegalArgumentException("Definition or definition name is null, not permitted.");
    		}
    		if (animation == null) {
    			throw new IllegalArgumentException("Animation for npc cannot be null.");
    		}
    		if (message == null || message.length < 1 || message.length > 4) {
    			throw new IllegalArgumentException("Amount of lines must be between 1 and 4 inclusive. ");
    		}
    		links.add(new DialogueLink(new NpcDialogue(definition, animation, message)));
    
    
    		return this;
    	}
    
    
    	public DialogueChain statement(String... messages) {
    		if (messages == null || messages.length == 0 || messages.length > 6) {
    			throw new IllegalArgumentException("Messages cannot be null and must contain between 1 and 5 elements.");
    		}
    		links.add(new DialogueLink(new StatementDialogue(messages)));
    
    
    		return this;
    	}
    Thank you for that! I will see how I can implement such a thing!
    Attached image
    Attached image
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work here!
    Reply With Quote  
     

  10. Thankful user:


  11. #36  
    Registered Member
    Join Date
    Nov 2009
    Posts
    519
    Thanks given
    135
    Thanks received
    10
    Rep Power
    32
    I dont have to directly include a plugin or anything? I can simple just start using kotlin expressions and kotlin extensions? I've been interested in kotlin watched some video. was kinda cool. def the new fad but its a growing language
    Reply With Quote  
     

  12. #37  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    23
    Posts
    3,415
    Thanks given
    7,254
    Thanks received
    1,938
    Rep Power
    3905
    Quote Originally Posted by aki2k4 View Post
    I dont have to directly include a plugin or anything? I can simple just start using kotlin expressions and kotlin extensions? I've been interested in kotlin watched some video. was kinda cool. def the new fad but its a growing language
    IntelliJ has a Kotlin plugin (I believe pre-installed). If you use IntelliJ, it will configure it all for you once you make your first Kotlin class.
    Attached image
    Attached image
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work here!
    Reply With Quote  
     

  13. #38  
    Registered Member
    Join Date
    Nov 2009
    Posts
    519
    Thanks given
    135
    Thanks received
    10
    Rep Power
    32
    Quote Originally Posted by arham 4 View Post
    IntelliJ has a Kotlin plugin (I believe pre-installed). If you use IntelliJ, it will configure it all for you once you make your first Kotlin class.
    other than that if i install kotlin plugin to eclipse will it auto configure my first kt class?
    Reply With Quote  
     

  14. #39  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    23
    Posts
    3,415
    Thanks given
    7,254
    Thanks received
    1,938
    Rep Power
    3905
    Quote Originally Posted by aki2k4 View Post
    other than that if i install kotlin plugin to eclipse will it auto configure my first kt class?
    I haven't used eclipse in years, so you're on your own for that :/

    Sent from my SM-G930P using Tapatalk
    Attached image
    Attached image
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work here!
    Reply With Quote  
     

  15. #40  
    Registered Member
    24th's Avatar
    Join Date
    Oct 2016
    Posts
    250
    Thanks given
    35
    Thanks received
    85
    Rep Power
    189
    Pretty nice, I've been using a similar system for the last 2-3 years. This is how dialogues should be handled, honestly.
    Reply With Quote  
     

Page 4 of 5 FirstFirst ... 2345 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Advanced Kotlin Dialogue System
    By CrazyPanda in forum Snippets
    Replies: 7
    Last Post: 04-07-2016, 02:16 AM
  2. Kotlin Based Dialogue System
    By PinocchioOrWot in forum Show-off
    Replies: 11
    Last Post: 02-10-2016, 06:18 AM
  3. Ruse dialogue system.
    By Lotr M eurth in forum Help
    Replies: 3
    Last Post: 12-31-2015, 06:26 PM
  4. [ANY] Dialogue System
    By frostbit3 in forum Tutorials
    Replies: 15
    Last Post: 06-27-2014, 11:18 AM
  5. is ther any tool that cleans java files up
    By T-Sex in forum Downloads
    Replies: 7
    Last Post: 08-03-2008, 01:39 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •