Page 1 of 1
Posted: 03 Dec 2008, 19:46
by woodslanding
I'd like to send the result of a boolean out a data port, but it requires a float. Are there conversions for this? I'm doing an if then else, but I always like clean code....
Nothing much out there on the web.
Thanks!
Posted: 03 Dec 2008, 20:08
by woodslanding
okay, I just wrote a custom function for it. no big deal.
Posted: 03 Dec 2008, 23:54
by woodslanding
agg. now I just want to print out the value of a boolean, and don't know how to do it....
my kingdom for a manual

Posted: 04 Dec 2008, 00:12
by woodslanding
geez, never mind AGAIN. :/
guess I'd still like to know how this is done, tho.
Posted: 04 Dec 2008, 08:48
by bsork
Unlike in C (and derivatives) where binary 0 is FALSE and everything else is TRUE, you have to convert the booleans to integers. I suspect that the internal values are 0 and 1 just like in the Usine modules - here's a convertion function:
Code: Select all
function boolToInt(b : boolean) : integer;
begin
if (b) then begin
result := 1;
end
else begin
result := 0;
end;
end;
(...and once again I have to add begin...end in an if-else-statement where it shouldn't be needed...)
Posted: 04 Dec 2008, 18:50
by woodslanding
Okay, that's what I did.
Just didn't want to have to put this in every script where I need to do the conversion....
Posted: 04 Dec 2008, 23:31
by bsork
Well, I don't I have anything better to offer, but you might consider from case to case whether storing booleans or integers (0 and 1) is the most effective. If you do a lot of testing on the values, I think boolean is the way to go, but if you're mostly storing and retrieving the data to send it out again, integers would often be better.
I tried some varieties of using typecasting to get integers from booleans without success. I wouldn't be at all surprised if there is a way that I don't know of. Olivier?