Author Topic: npc text scripting  (Read 12799 times)

aimaina

  • Administrator
  • Cutesterest
  • *****
  • Posts: 1320
  • Cutes: 211
    • View Profile
  • Pronouns: she/her
npc text scripting
« on: August 26, 2018, 08:52:38 PM »
im writing a damn npc text system again.... i wanna make it less bad than the cute witchy house one but i have run into a dilemma....

here is a sample script....
Code: [Select]
\if{level < 2}{
  Welcome to the KittyPlains. Eat Star Flowers to Level Up and become stronger.
}{
  \talk{2}
  {You can now jump over the Blocks.}
  {Good luck on your quest.}
}
the effect of the "if" command should be pretty intuitive: \if{condition}{text1}{text_2} displays text1 if condition is true, and text2 if condition is false
the "talk" command works like this: \talk{2}{text1}{text2} displays text1 if it is the first time you have talked to the npc, displays text2 if it is the second time, and for further talks it cycles between them

the problem is that i dont actually want the talk command to behave that way. i want it to be aware of branches in the dialogue, and display the first text if it is your first time visiting the particular branch where the talk command appears, the second text the second time, etc. that is, i want it to work this way:
Code: [Select]
[talk to NPC]
Welcome to the KittyPlains. Eat Star Flowers to Level Up and become stronger.
[level up to level 2]
[talk to NPC]
You can now jump over the Blocks.
[talk to NPC]
Good luck on your quest.
currently what happens is this:
Code: [Select]
[talk to NPC, first time]
Welcome to the KittyPlains. Eat Star Flowers to Level Up and become stronger.
[level up to level 2]
[talk to NPC, second time, displays second text of the talk command]
Good luck on your quest.
[talk to NPC, third time, cycles back to first text]
You can now jump over the Blocks.
it seems like it will be very hacky and awkward to make the "number of times talked" variable aware of what dialogue branch you are on, and hacky and awkward is exactly what i want to avoid with this text system....

im wondering if a certain vgperson has dealt with this issue before and has a smart solution..... or if anyone else has ideas.....
~Without love, the truth cannot be seen~

this is watermelon :watermelon: put her in your signature so she can achieve world domination

aimaina

  • Administrator
  • Cutesterest
  • *****
  • Posts: 1320
  • Cutes: 211
    • View Profile
  • Pronouns: she/her
Re: npc text scripting
« Reply #1 on: August 26, 2018, 09:09:46 PM »
ok i think i figured out a solution that isnt that bad..... i realized that each "talk" command can be uniquely identified by two things: the instance id of the calling npc, plus the position of the command in the npc text string (which i already need to store to process the command). so i use that data to build a map which stores the number of times each individual talk command has been activated, and i use that value instead of the generic "number of times talked" to determine which text to show, which i think gives the behaviour i want.....
~Without love, the truth cannot be seen~

this is watermelon :watermelon: put her in your signature so she can achieve world domination

vgperson

  • Cutest
  • ****
  • Posts: 258
  • Cutes: 110
  • guess i'll have to... make them fall.
    • View Profile
    • vgperson.com
Re: npc text scripting
« Reply #2 on: August 26, 2018, 09:34:36 PM »
Yeah, tracking variables that auto-pair with talk commands should work.

I would normally just manually manage a flag variable for this situation, because my system is mostly just a linear procession (with conditional branches) instead of having nested functions like that. This is how I would do it currently.

Code: [Select]
\if flag(Talked) == 0
   message 1
\if flag(Talked) == 1
   message 2
\if flag(Talked) == 2
   message 3

\flag(Talked, +1) // + means increment from current
\if flag(Talked) > 2
   \flag(Talked, 0) // set to 0

(Part of this working is a "starting value of 0" assumption like the one you can have in Game Maker; when a flag that didn't exist before is altered, it's treated as if it were originally 0. In fact, if a flag's value is 0, it's not even saved in the save file. This behavior is extremely useful for just adding flags as I need them.)

But if I were making a game that called for this a lot, I would add a switch statement to replace the ifs, and a function that encapsulates the end part:

Code: [Select]
\switch flag(Talked)
\case 0
   message 1
\case 1
   message 2
\case 2
   message 3
\end
\flagLoop(Talked, 0, 2)

And if I were really bothered about it I could just make a special \switch that incorporates flagLoop and maybe even checks the cases to know what values to loop. But yeah, not really common enough to warrant it in my case.
« Last Edit: August 26, 2018, 10:03:06 PM by vgperson »

dcco

  • Cutest
  • ****
  • Posts: 469
  • Cutes: 112
    • View Profile
Re: npc text scripting
« Reply #3 on: August 27, 2018, 02:39:27 AM »
make a whole custom pseudo-assembly instruction set with a bunch of custom codes for dialogue

wilde32

  • Cuter
  • ***
  • Posts: 237
  • Cutes: 24
    • View Profile
  • Pronouns: Consider replacing your battery.
Re: npc text scripting
« Reply #4 on: August 27, 2018, 03:52:57 AM »
 :dancedog:

aimaina

  • Administrator
  • Cutesterest
  • *****
  • Posts: 1320
  • Cutes: 211
    • View Profile
  • Pronouns: she/her
Re: npc text scripting
« Reply #5 on: August 27, 2018, 05:58:08 AM »
hmm i wonder how good an assembly style thing would be compared to what im doing..... it would be easier to parse probably so thats one advantage
~Without love, the truth cannot be seen~

this is watermelon :watermelon: put her in your signature so she can achieve world domination

aimaina

  • Administrator
  • Cutesterest
  • *****
  • Posts: 1320
  • Cutes: 211
    • View Profile
  • Pronouns: she/her
Re: npc text scripting
« Reply #6 on: August 27, 2018, 06:07:48 AM »
i just realized my amazing text system does not easily support the concept of "multiple text boxes for one speak action" so maybe ill try the assembly thing
~Without love, the truth cannot be seen~

this is watermelon :watermelon: put her in your signature so she can achieve world domination

aimaina

  • Administrator
  • Cutesterest
  • *****
  • Posts: 1320
  • Cutes: 211
    • View Profile
  • Pronouns: she/her
Re: npc text scripting
« Reply #7 on: August 27, 2018, 06:09:42 AM »
oh wait actually i think this is a deficiency of the npc object moreso than my parsing thingy
~Without love, the truth cannot be seen~

this is watermelon :watermelon: put her in your signature so she can achieve world domination

aimaina

  • Administrator
  • Cutesterest
  • *****
  • Posts: 1320
  • Cutes: 211
    • View Profile
  • Pronouns: she/her
Re: npc text scripting
« Reply #8 on: August 27, 2018, 09:52:35 AM »
wow i switched to an assembly-esque system and its so much better and easier to manage.....  i think its mostly because of the fact that its processed linearly like vg said her system does..... that seems like the way to go rather than whatever weird thing i was trying to do before

i think im learning that complex npc text is best treated as a "program" that starts executing when you talk to the npc, rather than just a block of data that you parse on each talk and feed to the npc object....
~Without love, the truth cannot be seen~

this is watermelon :watermelon: put her in your signature so she can achieve world domination

hubol

  • Cutesterest
  • ******
  • Posts: 1135
  • Cutes: 630
    • View Profile
    • hubolhubolhubol
Re: npc text scripting
« Reply #9 on: August 27, 2018, 12:06:24 PM »
nice!!!

dcco

  • Cutest
  • ****
  • Posts: 469
  • Cutes: 112
    • View Profile
Re: npc text scripting
« Reply #10 on: August 27, 2018, 01:55:48 PM »
nice - i had that idea because i was thinking about making a speech system too, and i was trying to think of the best way to do like looping / branching dialogue. nice to hear that it sounds like it works.

aimaina

  • Administrator
  • Cutesterest
  • *****
  • Posts: 1320
  • Cutes: 211
    • View Profile
  • Pronouns: she/her
Re: npc text scripting
« Reply #11 on: August 27, 2018, 06:09:17 PM »
here is an example of a npc interaction i just wrote..... this character normally says one of three lines when you talk to them, looping after the last line. but if you have examined a nearby locked door, they need to break out of that loop and unlock the door for you
Code: [Select]
top:
if {flag(kitty_town_door) == 1}
 . It seems you want to go to Kitty Town, well you look trustworthy, go ahead.
 set kitty_town_door 2
else
 . Do not fall in the holes, if your JMP is not strong enough you will need to restart.
 brk
 jmc {flag(kitty_town_door) == 1} top
 . Kitty Town is past the dangerous holes. I'm a Knight that protects the town.
 brk
 jmc {flag(kitty_town_door) == 1} top
 . I'm thirsty, should of brought a Water.
fi
heres what the code's do....
- top: or anything else ending in a colon is a label you can jump to
- if/else/fi works as you would expect
- the dot produces a textbox
- set lets you modify flags
- brk stops the current conversation, and resumes from the next line next time you talk to the npc. so for example if you do
. Text 1
. Text 2

you get a single conversation with two textboxes, whereas if you do
. Text 1
brk
. Text 2

you get one textbox per conversation
-  jmc is a conditional jump, used here to break out of the normal text loop if the flag is set
- when you reach the end of the code, the conversation ends and the "program counter" is reset to 0, so it will start from the top next time you speak to the npc
~Without love, the truth cannot be seen~

this is watermelon :watermelon: put her in your signature so she can achieve world domination

SquareWheel

  • Administrator
  • Cutester
  • *****
  • Posts: 802
  • Cutes: 139
    • View Profile
Re: npc text scripting
« Reply #12 on: August 27, 2018, 07:34:41 PM »
So are you writing a parser and translating all this to native instructions?  Seems like a lot of work over using your language's normal control structure for this.

Probably want to change "should of" to "should have".

vgperson

  • Cutest
  • ****
  • Posts: 258
  • Cutes: 110
  • guess i'll have to... make them fall.
    • View Profile
    • vgperson.com
Re: npc text scripting
« Reply #13 on: August 27, 2018, 09:00:46 PM »
The problem is that the normal control structures of game-oriented languages typically aren't inherently suited to "pause execution of this code here until the textbox is advanced, or until some other thing happens, or for a certain amount of time." So you just gotta make your own processing that is.

Also, didn't know you were the person leaving typo reports on raocow's JIGGLY ZONE LP. The Mystery is Solve'd

SquareWheel

  • Administrator
  • Cutester
  • *****
  • Posts: 802
  • Cutes: 139
    • View Profile
Re: npc text scripting
« Reply #14 on: August 27, 2018, 09:30:54 PM »
Hrmm, okay that makes sense.  And while you might be able to offload that to another thread and still run rendering/networking/whatever in the background, I don't think Gamemaker lets you do that sort of thing yet.

I didn't see the raocow thing but I am always happy to lend grammatical assistance.