How you can make actor.text to IF actor.text="text" ..

Talk about making games.

How you can make actor.text to IF actor.text="text" ..

Postby bat78 » Fri Mar 29, 2013 5:56 pm

Hello, i have a last question till i am done, so i will be short as i can.
I tryed to use arrays:
Code: Select all
char textactor[256]=actor.text; //does not work

I tryed also with that:
Code: Select all
int atoi(actor*str); //no effect


So i am in total confusion.. how i might be supposed to do run functions if the actor.text = "texthere" and different functions if the actor.text = "anothertexthere".
If someone have ideas for that maybe he can share? But i don't think that is quite possible easy.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: How you can make actor.text to IF actor.text="text" ..

Postby skydereign » Fri Mar 29, 2013 6:53 pm

To set a string equal to another, you have to use a string function.
Code: Select all
char textactor[256];
strcpy(textactor, actor.text);
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How you can make actor.text to IF actor.text="text" ..

Postby bat78 » Fri Mar 29, 2013 7:25 pm

strcpy relative to actor.text is already in use. Im reading text from file. So.. is there a way to make IF actor.text="choice 1" { ..
fgets? or atoi?
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: How you can make actor.text to IF actor.text="text" ..

Postby Hblade » Fri Mar 29, 2013 7:37 pm

If your using the file* method, all numbers can be stored within variables, like so:

heres your text file:
Code: Select all
playerX=45


if you want to use this, its simple. I could be wrong cause its been a while but I think it goes something like this:
fgetc(FILE, "playerX=%d", variable);

In your case, the choice. Instead of if text=, you can do if variable==1, (or what ever other number they would type in the text file)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: How you can make actor.text to IF actor.text="text" ..

Postby bat78 » Fri Mar 29, 2013 7:46 pm

Damn i am lost xD Where i have to put that.
fgetc's syntax accept two arguments as i remember, it wont happan with fgetc(FILE, "playerX=%d", i_Text); for sure, but what "playerX=%d" stands for?
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: How you can make actor.text to IF actor.text="text" ..

Postby Hblade » Fri Mar 29, 2013 8:27 pm

I may have been wrong in the way to do it xD

%d represents an integer variable, %d will become the value of the variable you mentioned after it :P
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: How you can make actor.text to IF actor.text="text" ..

Postby bat78 » Fri Mar 29, 2013 8:51 pm

You wrote "fgetc" and it accepts 2 parameters, are you sure it is fgetc not fgets, because fgets accepting 2 parameters and it converts string num.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: How you can make actor.text to IF actor.text="text" ..

Postby lcl » Fri Mar 29, 2013 11:00 pm

If you simply want to check if some text is same as some other text, use strcmp(). (Strcmp comes from string compare.)
Here's how to use it:

If you want to check if Actor1's text is "hello", and use it as a condition, you'd write this:
Code: Select all
if (strcmp(Actor1.text, "hello") == 0)
{
    //Then you add your conditional code here.
}

Notice that the strings are the same when strcmp() returns 0. You can think it like that there is 0 differences between the two strings -> they are the same.

I hope this helps you! :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: How you can make actor.text to IF actor.text="text" ..

Postby bat78 » Sat Mar 30, 2013 12:34 am

I don't have to test to make sure that takes effect ^-^ Thanks. +1
Also thanks hblade and drein for the responsability.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: How you can make actor.text to IF actor.text="text" ..

Postby Hblade » Sat Mar 30, 2013 6:37 am

Ahh I forgot about that lcl ^^
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest