Hello world :) hm, so i would like to make a chatbot. There's a few months a made it in flash AS3, but with GDScript, i don't know how to do that. May be it's possible to "translate" AS3 to GDScript?...

Before i made this (in flash) :

For example, i had a label for the answer called "att", and an inputtext called "lutilisateur". When the word "tchao" is detected in a text (for example, "So, i must go to the supermarket ; tchao Mann xD"), it happens this, for 1 answer :

var aok01:String = lutilisateur.text;
 if(aok01.indexOf("tchao") != -1){	att.text = "Aurevoir";}

when the word "bonjour" is detected, it happens this, for random awswers :

var listeFT:Array = ["Bonjour", "Salut", "Hello", "Coucou"];
var choixFT:String = listeFT[Math.floor(Math.random()*listeFT.length)]; 
if(aok01.indexOf("bonjour") != -1){	att.text = choixFT;}

(sorry for the indentation xD)

is it possible to do that with Godot?

Thanks for your advice :)

Alain

If you are wanting to find a string in another string, then the find function OR using in should work. For example:

var aok01 : String = lutilisateur.text;
# example using find
if (aok01.find("tchao") != -1):
	att.text = "Aurevoir"

# example using in
if "tchao" in aok01:
	att.text = "Aurevior

I do not think there is a function for finding if text exists in an array, but a function like this should make it doable:

func find_in_array(p_array : Array, p_what : String):
	for item in p_array:
		var find_result = p_what.find(item)
		if (find_result != -1):
			return find_result
	return -1

Then you can use it likes this:

var listeFT  = ["Bonjour", "Salut", "Hello", "Coucou"]
var choixFT = listeFT[floor(rand_range(0, listeFT.size()-1))]
if (find_in_array(aok01, listeFT) != -1):
	att.text = choixFT
6 days later

Thank you for theses advices TwistedTwileg. But i had a problem with "var listeFT = ["Bonjour", "Salut", "Hello", "Coucou"]" so i continue to search and i find the other part of the solution x). So i did it now. The game can find a word and display "1" answer, on random answers, and "simulate" et followed conversation :)... hm... work in progress =)

var response = String("default)" I highly suggest control+clicking that green String word. Godot has a built in documentation for its built-in classes. If you scroll through it I'm sure you're going to find all the functions you need.

a year later