I have this program, when it starts, i am unable to press numbers. By pressing F this turns the numbers on.
However, the result is, i have to hold down F to use the numbers. I thought declaring ignition as true would stick after i had released F. And pressing G would turn it false again, but to no avail.

Im new to the C after using Java.
Code:

bool ignition;
	ignition = false;


	if (AdventureGame.keypressed[DIK_F] && (ignition == false))
		ignition = true;

	if (AdventureGame.keypressed[DIK_G] && (ignition == true))
		ignition = false;

	if (AdventureGame.keypressed[DIK_0] && (ignition == true))
		GEARBOX.SetPositionX(-1),
		GEARBOX1.SetPositionX(20),
		GEARBOX2.SetPositionX(20),
		GEARBOX3.SetPositionX(20),
		GEARBOX4.SetPositionX(20),
		GEARBOX5.SetPositionX(20),
		GEARBOX6.SetPositionX(20);

	if (AdventureGame.keypressed[DIK_1] && (ignition == true))
		GEARBOX.SetPositionX(20),
		GEARBOX1.SetPositionX(-1),
		GEARBOX2.SetPositionX(20),
		GEARBOX3.SetPositionX(20),
		GEARBOX4.SetPositionX(20),
		GEARBOX5.SetPositionX(20),
		GEARBOX6.SetPositionX(20);

	if (AdventureGame.keypressed[DIK_2] && (ignition == true))
		GEARBOX.SetPositionX(20),
		GEARBOX1.SetPositionX(20),
		GEARBOX2.SetPositionX(-1),
		GEARBOX3.SetPositionX(20),
		GEARBOX4.SetPositionX(20),
		GEARBOX5.SetPositionX(20),
		GEARBOX6.SetPositionX(20);

	if (AdventureGame.keypressed[DIK_3] && (ignition == true))
		GEARBOX.SetPositionX(20),
		GEARBOX1.SetPositionX(20),
		GEARBOX2.SetPositionX(20),
		GEARBOX3.SetPositionX(-1),
		GEARBOX4.SetPositionX(20),
		GEARBOX5.SetPositionX(20),
		GEARBOX6.SetPositionX(20);

	if (AdventureGame.keypressed[DIK_4] && (ignition == true))
		GEARBOX.SetPositionX(20),
		GEARBOX1.SetPositionX(20),
		GEARBOX2.SetPositionX(20),
		GEARBOX3.SetPositionX(20),
		GEARBOX4.SetPositionX(-1),
		GEARBOX5.SetPositionX(20),
		GEARBOX6.SetPositionX(20);

	if (AdventureGame.keypressed[DIK_5] && (ignition == true))
		GEARBOX.SetPositionX(20),
		GEARBOX1.SetPositionX(20),
		GEARBOX2.SetPositionX(20),
		GEARBOX3.SetPositionX(20),
		GEARBOX4.SetPositionX(20),
		GEARBOX5.SetPositionX(-1),
		GEARBOX6.SetPositionX(20);

	if (AdventureGame.keypressed[DIK_6] && (ignition == true))
		GEARBOX.SetPositionX(20),
		GEARBOX1.SetPositionX(20),
		GEARBOX2.SetPositionX(20),
		GEARBOX3.SetPositionX(20),
		GEARBOX4.SetPositionX(20),
		GEARBOX5.SetPositionX(20),
		GEARBOX6.SetPositionX(-1);

Is the declaration of ignition inside the loop?
Then you shouldn't be surprised, you're recreating it and initializing it to false each time.

declaring ignition as true

That's an assignment, not a declaration. The declaration is bool ignition;

Im new to the C

Looks like C++ code to me.

(ignition == false)

Should be !ignition and ignition==true should be just ignition. That's not C++ - specific though, the same applies to Java.

bool ignition;
ignition = false;

Should be bool ignition=false;

Also this code, remember to use brackets to declare a block :

if(AdventureGame.keypressed[DIK_6]){
 /* code goes here */
}

Also I'm not sure if ur trying to optimize by this statement :

if (AdventureGame.keypressed[DIK_F] && (ignition == false))
		ignition = true;
 
if (AdventureGame.keypressed[DIK_G] && (ignition == true))
		ignition = false;

but you can just do this :

if(AdventureGame.keypressed[DIK_F] ) ignition = true;
else if(AdventureGame.keypressed[DIK_G]) ignition = false;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.