I am able to get a random word from a list in the javascript speak script and it speaks with:
function mathRandomInt(a, b) {
if (a > b) {
// Swap a and b to ensure a is smaller.
var c = a;
a = b;
b = c;
}
return Math.floor(Math.random() * (b - a + 1) + a);
}
var wordnum = mathRandomInt(1, 3);
var answord = [‘surprised’, ‘decided’, ‘included’];
var firstword = answord[(wordnum - 1)];
speak(firstword);
How do I use the variable firstword in the events?
GDevelop variables are not the same as javascript variables. To convert a javascript variable into a gdevelop variable, simply do:
runtimeScene.getVariables().get("myGdevelopVariable").setString(firstword);
You can then use the gdevelop variables actions and expressions with the variable myGdevelopVariable (in this example, of course you can modify te name of the variable however you want)
1 Like
Thanks for your help. Being new my learning curve is steep but when I finally actually did what you said it works!