Comunidad Game Maker

Ayuda => Preguntas y respuestas => Mensaje iniciado por: Mr.Dudas en Julio 27, 2012, 04:02:20 PM

Título: Guardar personajes
Publicado por: Mr.Dudas en Julio 27, 2012, 04:02:20 PM
Mi proyecto es un creador de animaciones,tiene una opción para crear propios personajes y mi pregunta es como hacer que cuando el jugador guarde el personaje creado,que solo se guarde el personaje y no todo el juego?y luego al cargar el personaje también lo mismo como lo hago?
Título: Re:Guardar personajes
Publicado por: Mgbu en Julio 27, 2012, 07:55:09 PM
Si los personajes son esa serie de puntos tenes que guardar las coordenadas de cada punto en un .txt
Seria algo asi:

tmp=file_text_open_write('save.txt')
file_text_write_string(tmp,o.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o.y)
file_text_writeln(tmp)
file_text_write_string(tmp,o1.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o1.y)
//...
file_text_close(tmp)

Luego para cargar:

tmp=file_text_open_read('save.txt')
o.x=file_text_read_string(tmp,0)
file_text_readln(tmp)
o.y=file_text_read_string(tmp,0)
file_text_readln(tmp)
o1.x=file_text_read_string(tmp,0)
file_text_readln(tmp)
o1.y=file_text_read_string(tmp,0)
//...
file_text_close(tmp)


Y el archivo quedaria algo asi como:

56 (Coordenada X de o)
76 (Coordenada Y de o)
23 (Coordenada X de o1)
65 (Coordenada Y de o1)
12 (Coordenada X de o2)
54 (Coordenada Y de o2)
...


Obviamente hay otras formas de guardar que no sea escribiendo uno abajo del otro, pero necesitarias procesar los string y otras cosas
Título: Re:Guardar personajes
Publicado por: Texic en Julio 27, 2012, 07:59:19 PM
Tendrías que guardar las características del personaje en un txt o un ini, por acá en esta sección hay varias preguntas sobre txt e ini, y sino tenés el manual. No es muy complicado el tema, con lo que más se te puede llegar a complicar es definir bien el path del txt (si es q usás txt), pero está bien explicado en los temas concernientes. Saludos!

PD: También podrías usar listas, hay una función que te permite guardarlas y cargarlas directamente en archivos
Título: Re:Guardar personajes
Publicado por: Mr.Dudas en Julio 27, 2012, 11:40:40 PM
Cita de: Mgbu en Julio 27, 2012, 07:55:09 PM
Si los personajes son esa serie de puntos tenes que guardar las coordenadas de cada punto en un .txt
Seria algo asi:

tmp=file_text_open_write('save.txt')
file_text_write_string(tmp,o.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o.y)
file_text_writeln(tmp)
file_text_write_string(tmp,o1.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o1.y)
//...
file_text_close(tmp)

Luego para cargar:

tmp=file_text_open_read('save.txt')
o.x=file_text_read_string(tmp,0)
file_text_readln(tmp)
o.y=file_text_read_string(tmp,0)
file_text_readln(tmp)
o1.x=file_text_read_string(tmp,0)
file_text_readln(tmp)
o1.y=file_text_read_string(tmp,0)
//...
file_text_close(tmp)


Y el archivo quedaria algo asi como:

56 (Coordenada X de o)
76 (Coordenada Y de o)
23 (Coordenada X de o1)
65 (Coordenada Y de o1)
12 (Coordenada X de o2)
54 (Coordenada Y de o2)
...


Obviamente hay otras formas de guardar que no sea escribiendo uno abajo del otro, pero necesitarias procesar los string y otras cosas
No me funciona el resultado:
CODIGO PARA GUARDAR:
tmp=file_text_open_write('save.txt')
file_text_write_string(tmp,o.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o.y)
file_text_writeln(tmp)
file_text_write_string(tmp,o2.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o2.y)
file_text_writeln(tmp)
file_text_write_string(tmp,o3.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o3.y)
file_text_writeln(tmp)
file_text_write_string(tmp,o4.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o4.y)
file_text_writeln(tmp)
file_text_write_string(tmp,o5.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o5.y)
file_text_writeln(tmp)
file_text_write_string(tmp,o6.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o6.y)
file_text_writeln(tmp)
file_text_write_string(tmp,o7.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o7.y)
file_text_writeln(tmp)
file_text_write_string(tmp,o8.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o9.y)
file_text_writeln(tmp)
file_text_write_string(tmp,o10.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o10.y)
file_text_writeln(tmp)
file_text_write_string(tmp,o11.x)
file_text_writeln(tmp)
file_text_write_string(tmp,o11.y)
file_text_close(tmp)
CODIGO PARA CARGAR:
tmp=file_text_open_read('save.txt')
o.x=file_text_read_string(tmp)
file_text_readln(tmp)
o.y=file_text_read_string(tmp)
file_text_readln(tmp)
o2.x=file_text_read_string(tmp)
file_text_readln(tmp)
o2.y=file_text_read_string(tmp)
file_text_readln(tmp)
o3.x=file_text_read_string(tmp)
file_text_readln(tmp)
o3.y=file_text_read_string(tmp)
file_text_readln(tmp)
o4.x=file_text_read_string(tmp)
file_text_readln(tmp)
o4.y=file_text_read_string(tmp)
file_text_readln(tmp)
o5.x=file_text_read_string(tmp)
file_text_readln(tmp)
o5.y=file_text_read_string(tmp)
file_text_readln(tmp)
o6.x=file_text_read_string(tmp)
file_text_readln(tmp)
o6.y=file_text_read_string(tmp)
file_text_readln(tmp)
o7.x=file_text_read_string(tmp)
file_text_readln(tmp)
o7.y=file_text_read_string(tmp)
file_text_readln(tmp)
o8.x=file_text_read_string(tmp)
file_text_readln(tmp)
o8.y=file_text_read_string(tmp)
file_text_readln(tmp)
o9.x=file_text_read_string(tmp)
file_text_readln(tmp)
o9.y=file_text_read_string(tmp)
file_text_readln(tmp)
o10.x=file_text_read_string(tmp)
file_text_readln(tmp)
o11.y=file_text_read_string(tmp)
file_text_readln(tmp)
o11.y=file_text_read_string(tmp)
file_text_close(tmp)
CUANDO ABRO EL SAVE.TXT PARA VER QUE HA ESCRITO:
(NADA SE QUEDA VACIO)
AL CARREGAR TODO SE VA X=0 Y=0
QUE HAGO????

PD: tuve que cambiar file_text_read_string(tmp,0)
por file_text_read_string(tmp) porque si no me daba error.
Título: Re:Guardar personajes
Publicado por: Mgbu en Julio 28, 2012, 04:13:20 PM
Pasame como quedo el editable asi se me hace mas facil