if text="text"?

Non-platform specific questions.

if text="text"?

Postby Hblade » Tue May 24, 2011 2:52 pm

Hi everybody :) I've tried many ways of having something happen IF the text is equal to this, or that... however I can't seem to get it to work :P Example codes I tried:
Code: Select all
//Try # 1:
if (strcmp(PWD.text, "c7756453f8")) {
    view.x+=640;
} //This test ended in it making the view go regardless of the password Oo

//Try # 2:
if (PWD.text == "c7756453f8") {
    view.x+=640;
}


Can anybody help with this? XD Im so confused as to why its not working
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: if text="text"?

Postby lcl » Tue May 24, 2011 3:00 pm

Code for checking if equal is this:
Code: Select all
if (strcmp(myLine, "hello") == 0)
{
    //blah…
}

0 is for that strcmp() compares the strings values (every char has own value) and returns the dfference between the lines' values. (I think.) :lol:
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: if text="text"?

Postby Hblade » Tue May 24, 2011 3:10 pm

Thank you so much! :)
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: if text="text"?

Postby lcl » Tue May 24, 2011 4:04 pm

Hblade wrote:Thank you so much! :)

You're welcome! :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: if text="text"?

Postby Game A Gogo » Tue May 24, 2011 8:42 pm

The documentation is where to look at for things like this... it explains 99% of all functions!
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: if text="text"?

Postby Hblade » Tue May 24, 2011 11:22 pm

True but I'd get my answeres from here faster, because my attention span.
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: if text="text"?

Postby Jagmaster » Mon Jun 13, 2011 1:04 pm

Will this check if string is empty?
Code: Select all
if(strcpy(string, 0,)==1)
{
//stuff
}

or this
Code: Select all
if(string==0)
{
//randomness
}

I'm assuming string variables start out as 0 unless otherwise specified.
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: if text="text"?

Postby skydereign » Mon Jun 13, 2011 5:53 pm

Well, you can do this if you want to check if it is an empty string.
Code: Select all
if(strcmp(text, "")==0)
{
    //
}


If you are checking if the string is null, you can do this, but that only applies if it is NULL (so you'd have to set it to NULL yourself).
Code: Select all
if(text==NULL)
{
    //
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest