How do I make a custom function?

image
So I have a few lines of code that will check if it is set to a value.
In the image I made a function that checks if pptName is set to pptVal and if it is already set to pptVal it would just pass to the next line of code.

But the issue here is if I call checkIfSet(<.some property key>, <.some property value>) it just tries to check if the value of the first argument is equal to the 2nd argument (in my cause it tries to check if BLENDER_EEVEE == CYCLES). But if you run the normal code(commented 2nd last line) it works fine. How can I make this new function?

It’s a basic Python question. Currently you’re assigning pptVal just to a name pptName which just happens to store value from engine attribute but attribute itself is unrelated now. If you want to change it, assign value to the attribute directly.

What do you gain by checking this anyway ? You do not use (and also can not use) the result of that check at all.

For your example: why not simply switch to cyles like so:

bpy.context.scene.render.engine = 'CYLES'


Edit:

Ohh… and python does not have the “traditional” call-by-reference… you may have look here:

Okay so after a little bit of testing and huge help from @Andrej and @Okidoki the way I should’ve gone about this is

But the reason why I did this was stupid and in the end this wasn’t solving my main issue welp.

This is still overthinking because even if shortened to:

def checkIfSet(pptName, pptVal):
    if pptName != pptVal:
        return pptVal

you could shorten it more:

def checkIfSet(pptName, pptVal):
        return pptVal

or even directly write

pptName = pptVal

…using the actual wanted name and value.

I still see no reason for a function at all…

You may have to elaborate this to get a more suited answer.

Actually the issue was that I have part my code that selects all markers in the video sequencer and deletes them (last part of screenshot)

image

This however causes a warning to shown when there are no markers.

And then I assumed all the values might need to be checked if they are assigned already or not. Stupidly overthunk, totally on me.

To solve it I then just add a marker then do the select and delete operations this works for both if there are markers in the video sequence tab or not.

But… this is a different topic…

For me ( in 3.6 ) the part with the sequencer does work but the selection for the marker is giving me already an context is in correct error…

( I’m also not sure if there should be a confirm = False in the parameters…)