sprintf not work

Non-platform specific questions.

sprintf not work

Postby equinox » Sat Mar 15, 2008 11:57 am

Hi,

this code non t work.

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

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

Why?

Tnk1000 for help.
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score

Re: sprintf not work

Postby edh » Sat Mar 15, 2008 12:13 pm

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");
User avatar
edh
 
Posts: 233
Joined: Thu Sep 13, 2007 12:17 am
Location: Maine, USA
Score: 14 Give a positive score

Re: sprintf not work

Postby Azou » Sat Mar 15, 2008 1:08 pm

Wow,It's working!!! ( I tried it,because i needed it!) :P
User avatar
Azou
 
Posts: 514
Joined: Thu Sep 13, 2007 1:12 pm
Score: 35 Give a positive score

Re: sprintf not work

Postby equinox » Sat Mar 15, 2008 1:20 pm

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;
Last edited by equinox on Sat Mar 15, 2008 2:17 pm, edited 2 times in total.
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score

Re: sprintf not work

Postby edh » Sat Mar 15, 2008 1:31 pm

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"};
User avatar
edh
 
Posts: 233
Joined: Thu Sep 13, 2007 12:17 am
Location: Maine, USA
Score: 14 Give a positive score

Re: sprintf not work

Postby equinox » Sat Mar 15, 2008 3:58 pm

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)....... ??
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score

Re: sprintf not work

Postby edh » Sat Mar 15, 2008 4:10 pm

: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. )
User avatar
edh
 
Posts: 233
Joined: Thu Sep 13, 2007 12:17 am
Location: Maine, USA
Score: 14 Give a positive score

Re: sprintf not work

Postby equinox » Sat Mar 15, 2008 5:31 pm

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)
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score

Re: sprintf not work

Postby edh » Sat Mar 15, 2008 5:39 pm

Yay! I'm glad it helped. :D
User avatar
edh
 
Posts: 233
Joined: Thu Sep 13, 2007 12:17 am
Location: Maine, USA
Score: 14 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron