A variable declared within a DEF block is absolutely invisible to any code that is not in that same DEF block, whether you use COMMON or not, whether you're in the same program slot or not.
COMMON DEF
Root / Programming Questions / [.]
MinxrodCreated:
You can access variables from outside a COMMON DEF statement but only in the same slot. You can only use variables in the slot they were defined.
A variable declared within a DEF block is absolutely invisible to any code that is not in that same DEF block, whether you use COMMON or not, whether you're in the same program slot or not.This is true, but you have to explicitly declare a variable with VAR or DIM for it to be local to the DEF to END section. The variables used to receive argument are automatically defined as local.
Also, check out this post.
https://www.smilebasicsource.com/forum?fpid=5460#post_5460
Also, check out this post. https://www.smilebasicsource.com/forum?fpid=5460#post_5460I looked at it. This pretty much solved all the problems I'm having so thanks everyone for the help :) I have another question though... Can arrays be used as arguments in DEFs?
I have another question though... Can arrays be used as arguments in DEFs?Absolutely!
I have a question myself about that. You can use an array in place of a variable and vice versa when calling the function you created. Is there a way to only accept a variable or only an array?I have another question though... Can arrays be used as arguments in DEFs?Absolutely!
Function parameters aren't checked for type. I discovered this when making a generic timing function, which calls another function and times how long it takes to run.
You can test it out easily:
COMMON DEF MYFUNC A$,B%,C# ?A$*2, B%, C# END MYFUNC 2, 3.1415, "TEST"You might expect that to fail because the parameters should have type, but it will work without errors. For this reason, you could theoretically pass an array or other variable, but in practice, with no way of reliably checking the type, you'll get errors when accessing it.
Function parameters aren't checked for type. I discovered this when making a generic timing function, which calls another function and times how long it takes to run. You can test it out easily:Wow, that's interesting :D Thanks for all the help from everyone by the wayCOMMON DEF MYFUNC A$,B%,C# ?A$*2, B%, C# END MYFUNC 2, 3.1415, "TEST"You might expect that to fail because the parameters should have type, but it will work without errors. For this reason, you could theoretically pass an array or other variable, but in practice, with no way of reliably checking the type, you'll get errors when accessing it.
Function parameters aren't checked for type. I discovered this when making a generic timing function, which calls another function and times how long it takes to run. You can test it out easily:Well that's crazy. I also noticed that you can't define two functions with the same name.COMMON DEF MYFUNC A$,B%,C# ?A$*2, B%, C# END MYFUNC 2, 3.1415, "TEST"You might expect that to fail because the parameters should have type, but it will work without errors. For this reason, you could theoretically pass an array or other variable, but in practice, with no way of reliably checking the type, you'll get errors when accessing it.
Thanks for all the help from everyone by the wayYou're welcome!