Random banter using context free grammar?
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Random banter using context free grammar?
https://wiki.wesnoth.org/Context-free_grammar
I would like to make a simple in game message using this context free grammar.
Basically like 2 random strings combined.
Say Hello or Howdy and Hero or Stranger.
How do I do that? I tried and I failed. Is it even possible?
Purpose would be some more randomized dialogs for traders and such.
By the way I got the new name generator working today for custom names. Hurray, it is actually part of Wesnoth 1.14!
I would like to make a simple in game message using this context free grammar.
Basically like 2 random strings combined.
Say Hello or Howdy and Hero or Stranger.
How do I do that? I tried and I failed. Is it even possible?
Purpose would be some more randomized dialogs for traders and such.
By the way I got the new name generator working today for custom names. Hurray, it is actually part of Wesnoth 1.14!
Re: Random banter using context free grammar?
Sure that´s possible. I´m using it in Strange Legacy for random greetings.
First your message must contain two variables.
As you know the $ means that the content of the variable is displayed.
Before displaying the message, you have to randomize these two variables with this code:
Be careful, as "Dr. Mausgewitz" and "Ni Hao" contains a space, which can lead to some unwanted effects, so you better keep them in quotes "".
Even so I do this, occasionally the space misses for some reason.
So the full code will be:
You can also create a new variable "dialogue" where you set the variable
For selecting a random image you might want to use this code:
Hopefully I could help you with that. Thanks again for supporting me with great images.
First your message must contain two variables.
Code: Select all
[message]
speaker=narrator
message= "$VariableA $VariableB"
[/message]
Before displaying the message, you have to randomize these two variables with this code:
Code: Select all
[set_variable]
name=VariableA
rand=Hello,Hi,Ni Hao,Bonjour,Salut,G'day,Ahoy,Ola
[/set_variable]
[set_variable]
name=VariableB
rand=Stranger,Ranger,Hero,Dr. Mausgewitz
[/set_variable]
Even so I do this, occasionally the space misses for some reason.
So the full code will be:
Code: Select all
[set_variable]
name=VariableA
rand=Hello,Hi,"Ni Hao",Bonjour,Salut,G'day,Ahoy,Ola
[/set_variable]
[set_variable]
name=VariableB
rand=Stranger,Ranger,Hero,"Dr. Mausgewitz"
[/set_variable]
[message]
speaker=narrator
message= "$VariableA $VariableB"
[/message]
For selecting a random image you might want to use this code:
Code: Select all
[set_variable]
name=randomportrait
rand=portraits/humans/mage-red.png,portraits/humans/footpad.png
[/set_variable]
[message]
image=$randomportrait
speaker=narrator
message= "$VariableA $VariableB"
[/message]
Hopefully I could help you with that. Thanks again for supporting me with great images.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Re: Random banter using context free grammar?
Ah, I should have looked through your latest versions!
Anyway that looks very doable to me. Thanks for the precise explanations.
I actually do not really know anything about code as a language, I Just copy fragment faithfully until they work. Amazingly it gives results based on the quality of the fragments. Sometimes our programmers cannot even copy the effects. lol.
If you have an art wishlist please keep me in the loop.
Anyway that looks very doable to me. Thanks for the precise explanations.
I actually do not really know anything about code as a language, I Just copy fragment faithfully until they work. Amazingly it gives results based on the quality of the fragments. Sometimes our programmers cannot even copy the effects. lol.
If you have an art wishlist please keep me in the loop.
Re: Random banter using context free grammar?
I`m glad I could help. If you need help with something else, just tell me.
The "Talk" Option is an older feature, but I also overworked it and added a chance to get a "random" mission. But I think it´s in the code for years now.
At the moment I don`t need any images, but thanks .
The "Talk" Option is an older feature, but I also overworked it and added a chance to get a "random" mission. But I think it´s in the code for years now.
At the moment I don`t need any images, but thanks .
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Random banter using context free grammar?
If you did want to use the context-free grammar system for more complex messages (probably not worth it for your simple example case though), you can do so in Lua. An advantage of context-free over variables is that you can easily have variations in message structure, without adding any additional code complexity.