Page 1 of 1

problem with strcpy (problem solved)

PostPosted: Tue Jun 24, 2008 2:19 pm
by stevenp
is there a way to insert a variable into this code?

strcpy(actor.text, " INSERT_VARIABLE_HERE ");}

its not working because it turns the variable into text

Re: problem with strcpy

PostPosted: Tue Jun 24, 2008 3:40 pm
by makslane
Are you want to use a numeric variable?

Re: problem with strcpy

PostPosted: Tue Jun 24, 2008 4:56 pm
by stevenp
in the game the variable will represent a number, yes

this is the current code


strcpy(DESC_lvls.text, "current level 0/5 \n mana cost : -- \n\n next level \n mana cost : 10 ");}


this is what i want it to be, so that i dont need to type it out for each level up, it updates by itself


strcpy(DESC_lvls.text, "current level 0/5 \n mana cost : VARIABLE1 \n\n next level \n mana cost : VARIABLE2 ");}

Re: problem with strcpy

PostPosted: Tue Jun 24, 2008 4:56 pm
by asmodeus
For string variables write this:
Code: Select all
strcpy(text, (char *)YourStringVar);

of
Code: Select all
sprintf(text, "%s", YourStringVar);

%s is for string.

For integer and real variables the same as above, %d for an integer variable and %f for real variables.
example:
Code: Select all
sprintf(text, "A string: %s\nAn integer: %d\nA float value: %f", "Hello!", 7, 3.4);

This make your text to this:
A string: Hello!
An integer: 7
A float value: 3.4

("\n" means new line)

could I help you?

Re: problem with strcpy

PostPosted: Tue Jun 24, 2008 5:02 pm
by stevenp
i just edited my previous post, so its more specific now

Re: problem with strcpy

PostPosted: Tue Jun 24, 2008 5:08 pm
by asmodeus
stevenp wrote:i just edited my previous post, so its more specific mow

okay, this should work:

sprintf(DESC_lvls.text, "current level 0/5 \n mana cost : %d \n\n next level \n mana cost : %d ", VARIABLE1, VARIABLE2);
if the vairable is a float variable, write %f instead of %d.

Re: problem with strcpy

PostPosted: Tue Jun 24, 2008 5:14 pm
by stevenp
thanks :D that makes it MUCH easier +1 point

lol

this was the code for each level for each skill in EL, it took SOOOO long


if (nec_skl==0){
strcpy(DESC_lvls.text, "current level 0/5 \n mana cost : -- \n\n next level \n mana cost : 10 ");}
if (nec_skl==1){
strcpy(DESC_lvls.text, "current level 1/5 \n mana cost : 10 \n\n next level \n mana cost : 8 ");}
if (nec_skl==2){
strcpy(DESC_lvls.text, "current level 2/5 \n mana cost : 8 \n\n next level \n mana cost : 6 ");}
if (nec_skl==3){
strcpy(DESC_lvls.text, "current level 3/5 \n mana cost : 6 \n\n next level \n mana cost : 4 ");}
if (nec_skl==4){
strcpy(DESC_lvls.text, "current level 4/5 \n mana cost : 4 \n\n next level \n mana cost : 2 ");}
if (nec_skl==5){
strcpy(DESC_lvls.text, "current level 5/5 \n mana cost : 2 \n\n next level \n mana cost : -- ");

there is 40 skills, so i had to do this 40 times :P all with diferent variables, in 40 different actors