SRL Archive - Suggestions

BoolToInt


Shuttleu

2010-12-10 17:24:06


function BoolToInt(TheBool: Boolean): Integer;
begin
if (TheBool) then
Result:= 1;
end;

i think this would allow us to easily make scripts without having to check the bool
example: without BoolToInt

TehBool:= True;
RandomArray:= [2, 4];

if TehBool then
Writeln(RandomArray[1])
else
Writeln(RandomArray[0]);
example: with BoolToInt

TehBool:= True;
RandomArray:= [2, 4];

Writeln(RandomArray[BoolToInt(TehBool)]);

~shut

Quickmarch

2010-12-10 17:33:15

Integer(BooleanHere); ?

Shuttleu

2010-12-10 17:34:41

or that ^

~shut

Sex

2010-12-10 18:28:55

Just use what he posted..?
Integer(Bool) does what you want it to do.

Shuttleu

2010-12-10 18:29:40

i know, but i mean it would be useful for it to be added to simba

~shut

Sex

2010-12-10 18:37:17

Why would it be useful? It would be redundant..
Edit: If you really want this, just wrap it.

function BoolToInt(Bool : boolean) : integer;
begin
result := Integer(Bool);
end;

Method

2010-12-10 18:38:24

Since when can you compare a boolean to an integer in Simba? For reference:

function BoolToInt(TheBool: Boolean): Integer;
begin
if (TheBool > 0) then
Result:= 1;
end;

Shuttleu

2010-12-10 18:43:13

whops, thats meant to be true :s

~shut

EDIT: oh, i didnt realise Integer(bool) returned 1 or

EDIT:
program new;
begin
writeln(integer(true));
end.
[Error] (4:22): Type mismatch at line 3
Compiling failed.

Sex

2010-12-10 18:44:02

Or just if (TheBool).

noidea

2010-12-10 18:53:45

Why cant we use bools as ints?

Wizzup?

2010-12-10 19:04:27

To my knowledge Pascal does not allow you to do so without explicit casting.

lordsaturn

2010-12-10 19:53:43

From: Wizzup?
To my knowledge Pascal does not allow you to do so without explicit casting.


Scar allows Integer(bool) which is why everyone is so confused.

noidea

2010-12-10 20:09:09

From: lordsaturn
Scar allows Integer(bool) which is why everyone is so confused.


using bools as integers. integer() changes it to a bool. using a bool as an integer is diff. because there is no 'conversion' needed. Bools are just 0 or 1.

lordsaturn

2010-12-13 00:46:27

From: noidea
using bools as integers. integer() changes it to a bool. using a bool as an integer is diff. because there is no 'conversion' needed. Bools are just 0 or 1.

really not quite sure what you are trying to say. b := a; doesn't work so I think a conversion is needed.

var a:boolean;b:integer;
begin
a:=true;
b := integer(a);
writeln(b); //outputs '1'
end.