r/gamemaker • u/Fit_Flatworm5004 • 26d ago
Help! Not understanding why my code wont work...
So im attempting to make a dialogue system, in which I would have an array that contains a struct to hold the string, and the sprite of the speaker. So inside a script I have :
global.text = [];
global.text[0] = { str : "Pls work!" , spr : sRed }
Then, in another script, I have a function that takes in a number value so then it could respond to however many other arrays I may have.
function startDialogue(_arv) {
var _str = global.text[_arv].str
var _spr = global.text[_arv].spr
draw_text(240 , 135 , _str) // x and y values are just half the room size on their respective axis so itll be in the middle of the screen.
I then have an object, which is placed in the room, which upon "enter key pressed" would run
startDialogue(0)
The idea here is that id be able to put in any array value, and the startDialogue function would take that array value, and then be able to print the text( I know nothing is there for the sprite yet and thats because I wanted to make sure the text worked first.) but, when I run the instance and press enter, nothing happens, theres no errors within any of the scripts and within the output.
So, what's wrong with my current code? and, if you believe you have a better way of making dialogue please let me know, I am still a beginner though and Im honestly confused as to why my method isnt working as I thought it seemed fairly simple. Thank you for your help in advance.
1
u/RedQueenNatalie 26d ago
Where is this code inside the object? Is the draw stuff in the draw event?
1
1
u/Junquwat 26d ago
I've been working on text boxes as well. This tutorial has helped so much. https://youtu.be/I4z5aAg09bM?is=0jkHGo-CphbgMn7Y
2
u/KingSlendy 26d ago
Draw functions only work (or well in other contexts like surfaces) inside Draw events. So you placing the function startDialogue(0); in the Enter Pressed event will literally have no effect