problem with strcpy (problem solved)

Talk about making games.

problem with strcpy (problem solved)

Postby stevenp » Tue Jun 24, 2008 2:19 pm

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
Last edited by stevenp on Tue Jun 24, 2008 5:19 pm, edited 1 time in total.
User avatar
stevenp
 
Posts: 403
Joined: Sat Dec 22, 2007 12:49 pm
Location: canada, ontario
Score: 16 Give a positive score

Re: problem with strcpy

Postby makslane » Tue Jun 24, 2008 3:40 pm

Are you want to use a numeric variable?
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: problem with strcpy

Postby stevenp » Tue Jun 24, 2008 4:56 pm

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 ");}
Last edited by stevenp on Tue Jun 24, 2008 5:01 pm, edited 2 times in total.
User avatar
stevenp
 
Posts: 403
Joined: Sat Dec 22, 2007 12:49 pm
Location: canada, ontario
Score: 16 Give a positive score

Re: problem with strcpy

Postby asmodeus » Tue Jun 24, 2008 4:56 pm

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?
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

Re: problem with strcpy

Postby stevenp » Tue Jun 24, 2008 5:02 pm

i just edited my previous post, so its more specific now
Last edited by stevenp on Tue Jun 24, 2008 5:10 pm, edited 3 times in total.
User avatar
stevenp
 
Posts: 403
Joined: Sat Dec 22, 2007 12:49 pm
Location: canada, ontario
Score: 16 Give a positive score

Re: problem with strcpy

Postby asmodeus » Tue Jun 24, 2008 5:08 pm

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.
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

Re: problem with strcpy

Postby stevenp » Tue Jun 24, 2008 5:14 pm

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
User avatar
stevenp
 
Posts: 403
Joined: Sat Dec 22, 2007 12:49 pm
Location: canada, ontario
Score: 16 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron