Notifications
Clear all

Fun With Boolean!


Cain532
Posts: 1280
Topic starter
(@cain532)
Noble Member
Joined: 10 years ago

So, I LOVE bools, they are some of the funnest bits of coding because of their versatility! So!, lets begin by explaining exactly what a bool is!

A bool is a variable that holds 2 values, true and false, (it can also be converted to an int value of 0 or 1)

also, Boolean and bool are the same thing 😉

One thing that makes bools very useful is that you can use them as methods! Just make sure you include a 'return' value of either true or false depending on what you want to do with it.

so lets say you have a lengthy function that you don't want to have to keep copy/pasting all over the place and using annoying if/else statements and so on.

Possibly one of the easiest ways to use bools would be to toggle. You can toggle between almost anything! Lets take a few examples

	
	private void checkBox1_CheckedChanged(object sender, EventArgs e)//simple CheckBox
	{//something interesting to note, remember what I said before? How bools contain 2 values; true and false. Well, what values does a CheckBox hold? ;) true and false. So, a CheckBox, is essentially a bool! Lets see a few ways we can use it
	byte[] On = {0xFF, 0xFF, 0xFF, 0xFF};//this can be any byte combiniation of course
	byte[] Off = {0x60, 0x00, 0x00, 0x00};
	/*One way we can do it, is with if/else statements*/
	if (checkBox1.Checked)//this means, if it returns a true value
	{
	PS3.SetMemory(0x00, On);
	}
	else if (!checkBox1.Checked)//notice the exclamation point, that means it searches for the OPPOSITE value held
	{
	PS3.SetMemory(0x00, Off);
	}
	/* That's all well and good, but here's a much simpler way of doing it */
	
	PS3.SetMemory(0x00, checkBox1.Checked ? On : Off);//this accomplishes the exact same thing! the '?' means it is checking for the bool value. then we have our 2 variables, it will always be in the order of bool ? true : false
	}
	
	//Lets say you're not using a CheckBox, you want to use a button!, Well, buttons don't hold values of true or false they are simply objects. So, we have to input a variable that we can use. so we can set it up this way
	
	bool This_Bool;//bools inherently start with a value of false
	private void button1_Clicked(object sender, EventArgs e)
	{
	    This_Bool = !This_Bool; //this means, each time the button is pressed, the bool This_Bool will become equal to the opposite of it's CURRENT value.
	PS3.SetMemory(0x00, This_Bool ? On : Off);
	//Now, we can change many other things with this same setup! ForeColor, BackColor, text, try things out! here are some examples
	
	button1.ForeColor = This_Bool ? Color.Green : Color.Black;//this means, if it's true, then it'll be green, false, it'll be black
	
	button1.Text = This_Bool ? "On" : "Off";
	}
	
	

So, we have just scratched the surface of bools! I hope this gives you all a good idea on what you could do with bools. play around with them and if you have questions, just ask!

Happy Modding!

Reply
2 Replies
anxify
Posts: 203
(@anxify)
Reputable Member
Joined: 9 years ago

So, I LOVE bools, they are some of the funnest bits of coding because of their versatility! So!, lets begin by explaining exactly what a bool is!

A bool is a variable that holds 2 values, true and false, (it can also be converted to an int value of 0 or 1)

also, Boolean and bool are the same thing 😉

One thing that makes bools very useful is that you can use them as methods! Just make sure you include a 'return' value of either true or false depending on what you want to do with it.

so lets say you have a lengthy function that you don't want to have to keep copy/pasting all over the place and using annoying if/else statements and so on.

Possibly one of the easiest ways to use bools would be to toggle. You can toggle between almost anything! Lets take a few examples

	
	private void checkBox1_CheckedChanged(object sender, EventArgs e)//simple CheckBox
	{//something interesting to note, remember what I said before? How bools contain 2 values; true and false. Well, what values does a CheckBox hold? ;) true and false. So, a CheckBox, is essentially a bool! Lets see a few ways we can use it
	byte[] On = {0xFF, 0xFF, 0xFF, 0xFF};//this can be any byte combiniation of course
	byte[] Off = {0x60, 0x00, 0x00, 0x00};
	/*One way we can do it, is with if/else statements*/
	if (checkBox1.Checked)//this means, if it returns a true value
	{
	PS3.SetMemory(0x00, On);
	}
	else if (!checkBox1.Checked)//notice the exclamation point, that means it searches for the OPPOSITE value held
	{
	PS3.SetMemory(0x00, Off);
	}
	/* That's all well and good, but here's a much simpler way of doing it */
	
	PS3.SetMemory(0x00, checkBox1.Checked ? On : Off);//this accomplishes the exact same thing! the '?' means it is checking for the bool value. then we have our 2 variables, it will always be in the order of bool ? true : false
	}
	
	//Lets say you're not using a CheckBox, you want to use a button!, Well, buttons don't hold values of true or false they are simply objects. So, we have to input a variable that we can use. so we can set it up this way
	
	bool This_Bool;//bools inherently start with a value of false
	private void button1_Clicked(object sender, EventArgs e)
	{
	    This_Bool = !This_Bool; //this means, each time the button is pressed, the bool This_Bool will become equal to the opposite of it's CURRENT value.
	PS3.SetMemory(0x00, This_Bool ? On : Off);
	//Now, we can change many other things with this same setup! ForeColor, BackColor, text, try things out! here are some examples
	
	button1.ForeColor = This_Bool ? Color.Green : Color.Black;//this means, if it's true, then it'll be green, false, it'll be black
	
	button1.Text = This_Bool ? "On" : "Off";
	}
	
	

So, we have just scratched the surface of bools! I hope this gives you all a good idea on what you could do with bools. play around with them and if you have questions, just ask!

Happy Modding!

This is gonna help out many others including myself thank pal 😀

Reply
LEGACYY
Posts: 2350
(@legacyy)
Noble Member
Joined: 9 years ago

m

So, I LOVE bools, they are some of the funnest bits of coding because of their versatility! So!, lets begin by explaining exactly what a bool is!

A bool is a variable that holds 2 values, true and false, (it can also be converted to an int value of 0 or 1)

also, Boolean and bool are the same thing 😉

One thing that makes bools very useful is that you can use them as methods! Just make sure you include a 'return' value of either true or false depending on what you want to do with it.

so lets say you have a lengthy function that you don't want to have to keep copy/pasting all over the place and using annoying if/else statements and so on.

Possibly one of the easiest ways to use bools would be to toggle. You can toggle between almost anything! Lets take a few examples

	
	private void checkBox1_CheckedChanged(object sender, EventArgs e)//simple CheckBox
	{//something interesting to note, remember what I said before? How bools contain 2 values; true and false. Well, what values does a CheckBox hold? ;) true and false. So, a CheckBox, is essentially a bool! Lets see a few ways we can use it
	byte[] On = {0xFF, 0xFF, 0xFF, 0xFF};//this can be any byte combiniation of course
	byte[] Off = {0x60, 0x00, 0x00, 0x00};
	/*One way we can do it, is with if/else statements*/
	if (checkBox1.Checked)//this means, if it returns a true value
	{
	PS3.SetMemory(0x00, On);
	}
	else if (!checkBox1.Checked)//notice the exclamation point, that means it searches for the OPPOSITE value held
	{
	PS3.SetMemory(0x00, Off);
	}
	/* That's all well and good, but here's a much simpler way of doing it */
	
	PS3.SetMemory(0x00, checkBox1.Checked ? On : Off);//this accomplishes the exact same thing! the '?' means it is checking for the bool value. then we have our 2 variables, it will always be in the order of bool ? true : false
	}
	
	//Lets say you're not using a CheckBox, you want to use a button!, Well, buttons don't hold values of true or false they are simply objects. So, we have to input a variable that we can use. so we can set it up this way
	
	bool This_Bool;//bools inherently start with a value of false
	private void button1_Clicked(object sender, EventArgs e)
	{
	    This_Bool = !This_Bool; //this means, each time the button is pressed, the bool This_Bool will become equal to the opposite of it's CURRENT value.
	PS3.SetMemory(0x00, This_Bool ? On : Off);
	//Now, we can change many other things with this same setup! ForeColor, BackColor, text, try things out! here are some examples
	
	button1.ForeColor = This_Bool ? Color.Green : Color.Black;//this means, if it's true, then it'll be green, false, it'll be black
	
	button1.Text = This_Bool ? "On" : "Off";
	}
	
	

So, we have just scratched the surface of bools! I hope this gives you all a good idea on what you could do with bools. play around with them and if you have questions, just ask!

Happy Modding!

My favorite type of coding, i swear you can do so much things with it as i need to learn more Thanks for teaching me stuff big homie Cain532 & Felony

Reply