Page 1 of 1

sprintf not work

PostPosted: Sat Mar 15, 2008 11:57 am
by equinox
Hi,

this code non t work.

char NAME[0] = "jiMMY";<---GLOBAL

sprintf(text, "%s", NAME[0]);<_-draw actor

Why?

Tnk1000 for help.

Re: sprintf not work

PostPosted: Sat Mar 15, 2008 12:13 pm
by edh
Name is a zero length array. So it has nothing in it.

Try this:

global
Code: Select all
char NAME[6];
strcpy(NAME, "jimmy\0");

Re: sprintf not work

PostPosted: Sat Mar 15, 2008 1:08 pm
by Azou
Wow,It's working!!! ( I tried it,because i needed it!) :P

Re: sprintf not work

PostPosted: Sat Mar 15, 2008 1:20 pm
by equinox
You are right. I now explain better.

I want to stamp a list of actor and their characteristics:

HERO [0] <--Joe Eroe
HP[0] = 10;
MP[0] = 8;
.............
HERO [1] <--Jimmy
HP[1] = 45;
MP[1] = 0;

Re: sprintf not work

PostPosted: Sat Mar 15, 2008 1:31 pm
by edh
Ok, so it is an array of arrays.

You can declare an array or strings (character arrays) like this.

Code: Select all
char *names[] = {"name_one", "name_two"};

Re: sprintf not work

PostPosted: Sat Mar 15, 2008 3:58 pm
by equinox
Well I have understood.

I thank really a lot as always you for the help.
________________________________________

A curiosity': in GAME MAKER:

draw_text (a)
draw_text (b)
draw_text (c) with an alone actor,

but in GE he is not possible to stamp + lines of text with an alone actor - > draw text?

sprintf(.... , y += 10)
sprintf(.... , y += 20)....... ??

Re: sprintf not work

PostPosted: Sat Mar 15, 2008 4:10 pm
by edh
:idea: By the way, you could also make structs to hold this data, and then make an array of structs.

:!: warning, advanced topic :P
Code: Select all
struct hero {
        char *name;
        int hp;
        int mp;
} heroes[2] = { {"hero one\0", 10, 10}, {"hero two\0", 5, 15} };


Then you could access it like this
Code: Select all
    sprintf(text, "name %d : %s\n", i, heroes[i].name);
    hp.textNumber = heroes[i].hp;
    mp.textNumber = heroes[i].mp;


(And, yes, I know what you mean about the difference between GM and GE. )

Re: sprintf not work

PostPosted: Sat Mar 15, 2008 5:31 pm
by equinox
I really glorify the example struct.

In GAME MAKER it doesn't exist.

But now thanks to you, i study it and everything that that you have taught me.

I now create a small example RPG.

infinitely: grazie1000...ops..:TNk1000( in ingles)

Re: sprintf not work

PostPosted: Sat Mar 15, 2008 5:39 pm
by edh
Yay! I'm glad it helped. :D