Comunidad Game Maker

Ayuda => Preguntas y respuestas => Mensaje iniciado por: Ares074 en Octubre 02, 2018, 12:21:46 AM

Título: Agregar numeros a string(Solucionado)
Publicado por: Ares074 en Octubre 02, 2018, 12:21:46 AM
Hola mi dudad es esta
Digamos que tengo el string str_code = string(v) quiero que al apretar la tecla up se le agrega un 1 al string  y si la aprieto una segunda vez se agregue otro uno
y si aprieto la tecla left se agregue un 2 y asi

Lo quiero es forma un código digamos que si el string el igual a 1112212 se ejecute un ataque

Queria usar la funcion keyboard_string; pero solo funciona con letras yo quiero usar las teclas up,right,down,left
Título: Re:Agregar numeros a string
Publicado por: Hezz en Octubre 02, 2018, 01:25:17 AM
Hola Ares074! Podés probar a añadir al mismo texto el valor que necesites, así:
[gml]str_code = str_code + string([el valor])[/gml]

Por ejemplo:
[gml]if (keyboard_check_pressed(vk_up)){
    str_code = str_code + string(1);
}
else if (keyboard_check_pressed(vk_left)){
    str_code = str_code + string(2);
}
etc...[/gml]
Título: Re:Agregar numeros a string
Publicado por: Ares074 en Octubre 02, 2018, 03:08:48 AM
Hola así es como tengo el código no me funciona

   str_code =  string(num)


if (keyboard_check_pressed(vk_up)){
    str_code = str_code + string(1);
    }




Al momento de apretar la tecla se agrega un 1 al string pero se quita enseguida
Título: Re:Agregar numeros a string
Publicado por: Clamud en Octubre 02, 2018, 04:54:28 AM
Debes borrar la linea de arriba
str_code =  string(num)
si no, en cada step la string se reinicia
Título: Re:Agregar numeros a string
Publicado por: Ares074 en Octubre 02, 2018, 05:21:48 AM
Sale error
DoAdd :: Execution Error
at gml_Object_obj_player2_StepNormalEvent_9 (line 7) -     str_code = str_code + string(1);
Título: Re:Agregar numeros a string
Publicado por: Arcadian en Octubre 02, 2018, 01:37:49 PM
Este código estaba bien pero va en el evento Create:

str_code =  string(num)

Y define el valor de num, o dará error.