Boolean function

Boolean function

PK_0
Observer Observer
539 Views
4 Replies
Message 1 of 5

Boolean function

PK_0
Observer
Observer

Hello. I need to write a function that returns a boolean value, which I can then use in an IF statement. I'm not entirely sure how to implement this correctly.
Could someone please provide an example of how this can be done? Any help or guidance would be greatly appreciated!

0 Likes
Accepted solutions (1)
540 Views
4 Replies
Replies (4)
Message 2 of 5

TK.421
Advisor
Advisor
here's a quick example. what are you looking to return?
 
bool b = $toolpath.ZRange.Maximum.Active

// if the status is false pop message box
// (to check if true use '1')
IF b == 0 {
    MESSAGE INFO "No"
}

the numbers never lie
0 Likes
Message 3 of 5

icse
Advisor
Advisor

Can you tell us in detail what your goal is?

 

heres an example of a function that returns a boolean value:

function main() {
	
	bool $yourBool = 0
	
	call yourFunction($yourBool)

	if $yourBool {
		message info "True"
	} else {
		message info "False"
	}
}

function yourFunction(output bool $b) {
	$b = 1
}

when you call yourFunction in the main method the value gets changed to true.

0 Likes
Message 4 of 5

PK_0
Observer
Observer

What would be macro alternative to this python code?:

 

def is_even(number):
if number % 2 == 0:
return True
else:
return False


number_to_check = 4

if is_even(number_to_check):
print("even")
else:
print("odd")

0 Likes
Message 5 of 5

icse
Advisor
Advisor
Accepted solution

i cant test it atm but it should look something like this:

 

function is_even(int $number, output bool $result) {
	if ($number % 2) == 0 {
		$result = True
	} else {
		$result = False
	}
}

function main() {
	int $number_to_check = 4
	
	bool $even = 0
	Call is_even($number_to_check,$even)
	
	if $even {
		message info "Even"
	} else {
		message info "Odd"
	}
}
0 Likes