Problems with ifs

Game Editor comments and discussion.

Problems with ifs

Postby regine » Fri Mar 21, 2008 8:39 pm

Code: Select all
if{code.text == code2.text}
{
    strcpy(code.text, "OK");
}


Whats false in this code?
My project: Packs Adventure
Now finished: Packs Adventure Demo:http://game-editor.com/forum/viewtopic.php?f=4&t=3491
Demo features:
Level 1-3
Leveleditor
Full edition features:
50 Levels
Big Leveleditor
Bonus features
Fighting mode
...and more
regine
 
Posts: 109
Joined: Mon Aug 15, 2005 7:19 pm
Location: Germany
Score: 1 Give a positive score

Re: Problems with ifs

Postby edh » Fri Mar 21, 2008 9:08 pm

You cannot compare arrays of characters with ==, if you try and they are not the same array, then that is false.

for example,
Code: Select all
char [] one = "a\0";
char [] two = "a\0";

if (one == two)
{
 // the address is the same
}

if (one == one)
{
 // the address is the same
}

if (strcmp(one, two) == 0)
{
  // the values are the same
}




You may be asking "why the f do I have to use strcmp(x, y) == 0?

Because strcmp is a lexical comparison. If x is < y then you will get a negative result from strcmp(x, y), zero for equality and a positive number for y > x.
User avatar
edh
 
Posts: 233
Joined: Thu Sep 13, 2007 12:17 am
Location: Maine, USA
Score: 14 Give a positive score

Re: Problems with ifs

Postby regine » Fri Mar 21, 2008 9:11 pm

THX I will try if it is working.

€dit: Declaration Error...
My project: Packs Adventure
Now finished: Packs Adventure Demo:http://game-editor.com/forum/viewtopic.php?f=4&t=3491
Demo features:
Level 1-3
Leveleditor
Full edition features:
50 Levels
Big Leveleditor
Bonus features
Fighting mode
...and more
regine
 
Posts: 109
Joined: Mon Aug 15, 2005 7:19 pm
Location: Germany
Score: 1 Give a positive score

Re: Problems with ifs

Postby edh » Fri Mar 21, 2008 10:40 pm

I wrote it quickly. I don't program in C normally, so I make a simple mistake.
You could change it to

Code: Select all
char * one = "a\0";


or

Code: Select all
char one[] = "a\0";


Your choice.
User avatar
edh
 
Posts: 233
Joined: Thu Sep 13, 2007 12:17 am
Location: Maine, USA
Score: 14 Give a positive score

Re: Problems with ifs

Postby regine » Fri Mar 21, 2008 10:57 pm

With one it says Redeclaration of parameter one but when i use two and three it is working. Is that a problem?

€dit: I started the game and it closed itself. Then i reopened GE and renentered the code and it was working.
€dit2: I want to write a copy protection with this. I already wrote a tool that can save license keys with that you can start the game. Is it compatible with this?

I mean iam doing something like this:

Starting the tool -> Writing license keys -> saving them -> start the copy protection of the game -> it loads the codes -> if the user enters one of these codes the game is activated

Is there any way to do that with this code?
My project: Packs Adventure
Now finished: Packs Adventure Demo:http://game-editor.com/forum/viewtopic.php?f=4&t=3491
Demo features:
Level 1-3
Leveleditor
Full edition features:
50 Levels
Big Leveleditor
Bonus features
Fighting mode
...and more
regine
 
Posts: 109
Joined: Mon Aug 15, 2005 7:19 pm
Location: Germany
Score: 1 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron