Page 1 of 1

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

PostPosted: Fri Mar 29, 2013 5:56 pm
by bat78
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.

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

PostPosted: Fri Mar 29, 2013 6:53 pm
by skydereign
To set a string equal to another, you have to use a string function.
Code: Select all
char textactor[256];
strcpy(textactor, actor.text);

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

PostPosted: Fri Mar 29, 2013 7:25 pm
by bat78
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?

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

PostPosted: Fri Mar 29, 2013 7:37 pm
by Hblade
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)

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

PostPosted: Fri Mar 29, 2013 7:46 pm
by bat78
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?

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

PostPosted: Fri Mar 29, 2013 8:27 pm
by Hblade
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

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

PostPosted: Fri Mar 29, 2013 8:51 pm
by bat78
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.

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

PostPosted: Fri Mar 29, 2013 11:00 pm
by lcl
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! :)

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

PostPosted: Sat Mar 30, 2013 12:34 am
by bat78
I don't have to test to make sure that takes effect ^-^ Thanks. +1
Also thanks hblade and drein for the responsability.

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

PostPosted: Sat Mar 30, 2013 6:37 am
by Hblade
Ahh I forgot about that lcl ^^