#conversation help

69 messages · Page 1 of 1 (latest)

sweet pumice
#

I'm trying to do a conversation code on my own. I'm trying to do it in a way that the textbox object has a conv = [] array and i can add the different texts thru the Creation Code in the room, however that doesn't seem to help. How can I fix this? Or is there any more efficient way to implement the conversation system?

wet rampart
#

Can you give more context on how the conversation should work for your game?

#

I once programmed a conversation in the style of a classic rpg.
For that I made a ds_grid that contained the information of the persons sprite (face), the persons name and the text itself. It looked like this
conversationGrid = [
[sFaceMerchant, "Merchant", "Hello young traveller, what can I do for you?"],
[sFaceJohn, "Traveller John", "Hi, can you give me information of a specific case?"],
...
]

#

With this I just needed a variable that checked at which point of the conversation I was and it cycled through the whole thing.

sweet pumice
sweet pumice
#

I'm not sure if that answers you question correctly, sorry

wet rampart
#

Ah I see

sweet pumice
#

and then in the Creation code I did this

#

it gives me the error

Push :: Execution Error - Variable Index [1] out of range [0] - -6.conv(100019,1)```
wet rampart
#

Yep this would work if you have specific dialogues for the different rooms

#

Hm, are you reading the conv array somewhere?

#

It seemd like it tries to read the position 1 of the array but the size GMS checks is set to 0

sweet pumice
#
draw_text(xstartt+padding, ystartt+padding-3, conv[1])```
wet rampart
sweet pumice
#

True

wet rampart
#

That should show you in the console what's actually standing there. It might get an error because conv[1] is not declaed every time and thus draw_text() has nothing to draw and throws an error message instead

sweet pumice
sweet pumice
#

___________________________________________
############################################################################################
ERROR in action number 1
of Draw Event for object oTextbox:
Push :: Execution Error - Variable Index [0] out of range [0] - -6.conv(100019,0)
 at gml_Object_oTextbox_Draw_64 (line 12) -        show_debug_message($"conv[0]: {conv[0]}");
############################################################################################
gml_Object_oTextbox_Draw_64 (line 12)

wet rampart
#

Ou lala

#

if you go to your creation code of the textbox instance and write
conv = ["", ""];

It should work

sweet pumice
#

Wait, I realized the problem

#

The conv array is at the create event of the textbox object, but i was putting the conv = ["", ""]; in another instance

#

I'll try this

wet rampart
#

I see

#

So it works for now?

sweet pumice
#

___________________________________________
############################################################################################
ERROR in action number 1
of Draw Event for object oTextbox:
Push :: Execution Error - Variable Index [0] out of range [0] - -6.conv(100020,0)
 at gml_Object_oTextbox_Draw_64 (line 12) -        show_debug_message($"conv[0]: {conv[0]}");
############################################################################################
gml_Object_oTextbox_Draw_64 (line 12)
wet rampart
sweet pumice
wet rampart
#

Okay, so
I'd still put
conv = ["", ""];
into the create event of oTextbox

#

Because that's the safest method for sure

sweet pumice
#

So, I should always add new elements into the array to make it bigger whenever a conversation is bigger than the current number of elements in the array?

wet rampart
#

Then for the draw event, you can disable the "show_debug_message()" lines and question the program for the array like this

if (array_length(conv) >= 2) draw_text(xstartt+padding, ystartt+padding-3, conv[1]);

wet rampart
#

conv = ["", ""];
conv = ["Hello", "World"];
//This will override the array

sweet pumice
wet rampart
#

If you have conv = ["", ""];
Facts are: The array conv has a size of 2; conv[0] = ""; conv[1] = "";
That's a safe option to have

After that every line that you write concerning this array, may override it and change the value of conv[0] conv[1] and so forth

#

You can muster it like this. You have a worker that has to collect apples with a basket. It's always safe for the worker to have an empty basket that can hold two apples.
If he were to come with NO basket at all, he would get fired --> ERROR

sweet pumice
#

Oh

wet rampart
#

So you can think of the array like a basket that can hold stuff. And what's also good to know is that arrays need to know their final size pretty early

The worker can't just magically increase the size of his basket (array) to hold MORE than 2 apples (values). Instead he has to come with a bigger basket (array) right at the start of his work

sweet pumice
#

I got that

#

My question now is how I can change those values in the creation code

#

and for it to be unique for every instance that i want to have a different conversation for

wet rampart
#

I'm finally on my PC so I can check in on that 🙂

sweet pumice
#

kk

wet rampart
#

Okay so firstly instead of running through every room and put the new dialogues in the Creation code you can use the "Room Start" Event inside of oTextbox

#

Here I set up a switch statement to check in what kind of Room we're at right now and then it fills in the conversation

#

Now to have different dialogue choices for every instance there are alot of ways to make that possible

#

One possibility is:

  1. Your player collides/interacts with that specific instance
  2. Then you check for other variables for example if you've already spoken to them or have their specific quest item
  3. Then you set up the conv-Array for oTextbox
sweet pumice
#

I'll try that

wet rampart
#

Another possibility might be:

  1. You've already declared EVERY dialogue right at the start of the game - INSIDE of the oTextbox Create Event. But not in the conv-Array, instead they could be stored in lots of different array like: merchantGreet, merchantBuy, merchantSell, daisyHub, daisyDesert, daisyCastle, daisyCaptured
  2. Your player collides/interacts with an instance that you cant to talk with
  3. You check who the other instance, what room you are in, what objectives are already done etc.
  4. You copy one of the already declared arrays onto the conv-Array. That might look like this:
    var _len = array_length(oTextbox.daisyCastle);
    array_copy(oTextbox.conv, 0, oTextbox.daisyCastle, 0, _len);
#

Alright ^^

sweet pumice
wet rampart
#

Yes

#

Or globally but the idea would be that all conversations are already declared and known when you start up the game. oTextbox just has to know when to use which conversation basically

sweet pumice
#

Could I do something like, make the textbox object a child of the pEntity object, and then add in the variable definition of an entity an entry to check which conversation to start?

wet rampart
#

Wdym exactly?

sweet pumice
#

Make the textbox object a child of the parent entity, so that all entity objects are "linked" to the textbox object's conv

#

And in the textbox object add a variable definition for which conversation to start

wet rampart
#

Ah I see!

#

Yeah that makes sense

sweet pumice
#

Is that a good method?

wet rampart
#

Tbh I don't know since I never tried but sounds like a possible solution 🙂

sweet pumice
#

Alright

#

Thanks