#conversation help
69 messages · Page 1 of 1 (latest)
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.
Yeah, thats similar of the thing I want to do
My approach now was putting an empty array at the Create event from the Textbox object, and then filling out the array in the Creation Code at the room editor for each object
I'm not sure if that answers you question correctly, sorry
Ah I see
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)```
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
When it displays the text
draw_text(xstartt+padding, ystartt+padding-3, conv[1])```
What's good for debug purposes is to write a line like this right before this:
show_debug_message($"conv[0]: {conv[0]}");
show_debug_message($"conv[1]: {conv[1]}");
True
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
Wouldn't that still give an error tho?
Oh
___________________________________________
############################################################################################
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)
Ou lala
if you go to your creation code of the textbox instance and write
conv = ["", ""];
It should work
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
___________________________________________
############################################################################################
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)
What object holds this creation code?
oSign, child of the pEntity object
Okay, so
I'd still put
conv = ["", ""];
into the create event of oTextbox
Because that's the safest method for sure
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?
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]);
No that's not it. If you have for examples these two lines;
conv = ["", ""];
conv = ["Hello", "World"];
//This will override the array
Yes, but would it override it in the Creation Code?
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
Oh
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
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
I'm finally on my PC so I can check in on that 🙂
kk
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:
- Your player collides/interacts with that specific instance
- Then you check for other variables for example if you've already spoken to them or have their specific quest item
- Then you set up the conv-Array for oTextbox
I'll try that
Another possibility might be:
- 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
- Your player collides/interacts with an instance that you cant to talk with
- You check who the other instance, what room you are in, what objectives are already done etc.
- 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 ^^
In the second point, you mean like setting all of the conversations inside the create event?
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
Okay
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?
Wdym exactly?
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
Is that a good method?
Tbh I don't know since I never tried but sounds like a possible solution 🙂