AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Bool (https://forums.alliedmods.net/showthread.php?t=24376)

mysticssjgoku4 02-20-2006 17:38

Bool
 
Argh, I've been coding for a while, and took a huge break.
The thing is, I never learned what bool is or how to use it.

I read a short 2 setence explaination on what they are, they hold an option of true or false.

Ok.

Now I have a few questions regarding boolean variables.


1) How do I get the state of the bool variable?

Example:
new bool:coords[3]

From my understanding, it is false my default. Now, how would I go about seeing what the state of it is anyhow, in an "IF()" statement?

This is what I've tried

Code:
if(bool:j1[2] == true) {

2) What is the variable to use in a client_print() function to echo the state of the bool?
Example: client_print(id,print_chat,"State: %s",bool:coords)

I need to know what symbol (%s, %i, etc).


Thanks.

Charr 02-20-2006 17:48

A bool is similar to a float in that you only have to declare bool: when you create it.

When you use it in a if() its:
Code:
new bool:blah = false; blah = true; if(blah == true) { }

I believe a bool is an interger, but I am not sure.

mysticssjgoku4 02-20-2006 17:51

ok, but I'm using it as an array.

Charr 02-20-2006 17:55

Then it would be
Code:
new bool:blah[2];

And a wya you can check the value of the bool is:
Code:
client_print(x,print_x,"%d",blah[x] ? "true" : "false");

mysticssjgoku4 02-20-2006 18:05

1 Attachment(s)
Quote:

Originally Posted by Charr
Then it would be
Code:
new bool:blah[2];

And a wya you can check the value of the bool is:
Code:
client_print(x,print_x,"%d",blah[x] ? "true" : "false");

Ok, so how would I go about using that in an IF() statement?

This image below, makes me think that I am doing the true/false wrong in the IF() statements for the bools. Right? Wrong?

Twilight Suzuka 02-20-2006 18:16

A bool is NOT an integer. A bool is a boolean value; true or false, 1 or 0.

You also need to use a strong tag: Bool: if you want to use it like that, otherwise you'll get tag warnings.

Its only similarity to a float is that, in PAWN, it is the size of one cell, and it is declared using a tag.

mysticssjgoku4 02-20-2006 18:31

Quote:

Originally Posted by Twilight Suzuka
A bool is NOT an integer. A bool is a boolean value; true or false, 1 or 0.

You also need to use a strong tag: Bool: if you want to use it like that, otherwise you'll get tag warnings.

Its only similarity to a float is that, in PAWN, it is the size of one cell, and it is declared using a tag.

So, what I'll have to do is create 2 serparate pairs of variables? Toggles and coord variableS?

v3x 02-20-2006 19:12

Yeah.

VEN 02-23-2006 06:58

In pawn:

In IF statement you can do
Code:
if (myboolvar) // if myboolvar is true
Code:
if (!myboolvar) // if myboolvar is false

In print you can do
Code:
server_print("State: %d", myboolvar) // if myboolvar is true you'll get "State: 1" in other case "State: 0"

Xanimos 02-23-2006 07:30

Quote:

Originally Posted by VEN
In pawn:

In IF statement you can do
Code:
if (myboolvar) // if myboolvar is true
Code:
if (!myboolvar) // if myboolvar is false

In print you can do
Code:
server_print("State: %d", myboolvar) // if myboolvar is true you'll get "State: 1" in other case "State: 0"

I prefer
Code:
server_print("State:%s" , myboolvar ? "true" : "false")


All times are GMT -4. The time now is 20:21.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.