Welcome to %s forums

BrainModular Users Forum

Login Register

scripts--converting to and from booleans

I need help on a Patch
Post Reply
woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 03 Dec 2008, 19:46

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!
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 03 Dec 2008, 20:08

okay, I just wrote a custom function for it. no big deal.
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 03 Dec 2008, 23:54

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 ;)
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 04 Dec 2008, 00:12

geez, never mind AGAIN. :/

guess I'd still like to know how this is done, tho.
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 04 Dec 2008, 08:48

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...)
Bjørn S

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 04 Dec 2008, 18:50

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....
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 04 Dec 2008, 23:31

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?
Bjørn S

Post Reply

Who is online

Users browsing this forum: No registered users and 46 guests