I am try to create some custom macros. How does karel pass varying number of constants into subroutines without faulting. For example: grip part (1,2). If I us argument registers in the subroutine as soon as I make it to a AR in which there is no value it will fault. How does karel do it? In grippart I can use one constant or 10, it doesn't matter. If I create my own macro I have to have the same number of AR in the subroutine as I do in the main program. Is there any way to look at an AR and if there is no value to pass through without fault?
Passing varying number of constants
-
Ciero -
July 26, 2013 at 2:18 PM -
Thread is Resolved
-
-
1. Figure out the max number of arguments that are possible. Then add one to that number. Then use that number in all of your calls.
2. The first argument is the number of arguments used/needed. For example if you needed 3 arguments and your max number possible is 5, then your argument string would be
(3, X1, X2, X3, X4, X5)
3. Any unused arguments get assigned a value.
4. Add logic when you read the argument to ignore the unused arguments. For the example you would ignore the X4 and X5 argument.