Returnvalues, or how to get the value of a var in srt change
Moderators: JRL, Dorian (MJT support)
-
- Newbie
- Posts: 14
- Joined: Fri Aug 20, 2010 9:08 am
Returnvalues, or how to get the value of a var in srt change
Hi
i am still evalutaing macshed and
i tried to do a small recursive implementation of the fac function(x!)
i found that variables are not recursive save so the values in an inner recursion are the same like in the outer , i found something about localvars=1 but didnt changed anything
so i implemented a mini stack to save the values
i ended with this:
[code]
let>stack_head=
srt>push
ASS>mystack_0,stackisassigned
if>stackisassigned=FALSE
let>mystack_0=0
endif
add>mystack_0,1
let>mystack_%mystack_0%=%push_var_1%
END>push
srt>pop
let>pop_var_1=mystack_%mystack_0%
sub>mystack_0,1
END>pop
srt>fac
if>fac_var_1>0
sub>fac_var_1,1
gosub>push,fac_var_1
gosub>fac,%fac_var_1%,%fac_var_2%
gosub>pop,x
let>fac_var_2={%fac_var_2% * (%pop_var_1%+1)}
else
let>fac_var_2=1
endif
END>fac
gosub>fac,5,result
let>result=fac_var_2
mdl>result
[/code]
now the problem :
To get the result (which should be in Variable result? (or in x for the call of pop)) i must explicit get it from the artificial variable fac_var2 or pop_var_2
are there any function concepts i am missing ?
is there a better way to do this ??
how to get variables automaticly pushed and poped like in ???
regards
dj
i am still evalutaing macshed and
i tried to do a small recursive implementation of the fac function(x!)
i found that variables are not recursive save so the values in an inner recursion are the same like in the outer , i found something about localvars=1 but didnt changed anything
so i implemented a mini stack to save the values
i ended with this:
[code]
let>stack_head=
srt>push
ASS>mystack_0,stackisassigned
if>stackisassigned=FALSE
let>mystack_0=0
endif
add>mystack_0,1
let>mystack_%mystack_0%=%push_var_1%
END>push
srt>pop
let>pop_var_1=mystack_%mystack_0%
sub>mystack_0,1
END>pop
srt>fac
if>fac_var_1>0
sub>fac_var_1,1
gosub>push,fac_var_1
gosub>fac,%fac_var_1%,%fac_var_2%
gosub>pop,x
let>fac_var_2={%fac_var_2% * (%pop_var_1%+1)}
else
let>fac_var_2=1
endif
END>fac
gosub>fac,5,result
let>result=fac_var_2
mdl>result
[/code]
now the problem :
To get the result (which should be in Variable result? (or in x for the call of pop)) i must explicit get it from the artificial variable fac_var2 or pop_var_2
are there any function concepts i am missing ?
is there a better way to do this ??
how to get variables automaticly pushed and poped like in ???
regards
dj
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Macro Scheduler's subroutines are just subroutines. Not functions. Functions return a result. Subroutines don't. They also can't be called inline in a calculation. They are just blocks of code you can call for convenience. Hence why you can't really do this recursively in MacroScript. You can of course use a global variable for the result. I usually prefix the variable name with the name of the subroutine to avoid confusion.
Of course you could use VBScript which DOES have functions:
VBSTART
function factorial(N)
if N = 0 then
factorial = 1
exit function
end if
factorial = N * factorial(N-1)
end function
VBEND
VBEval>factorial(5),fac
Of course you could use VBScript which DOES have functions:
VBSTART
function factorial(N)
if N = 0 then
factorial = 1
exit function
end if
factorial = N * factorial(N-1)
end function
VBEND
VBEval>factorial(5),fac
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 14
- Joined: Fri Aug 20, 2010 9:08 am
Hi Macus,
thanks for your quick answer
i thought already about doing it in VBScript but i have 2 problems with iT:
1 is there is no debugging and very rare error information
2 is the fac was my first try to get into it what i wanna really implement is a backtraking thru a maze (wich i build up with macroscheduler finding images with FIP> and therefore i have an ARRAY GAMEFIELD[%Xi%,%Yi%]
how can i pass that to vbscript ? giving the first element as a pointer?
i also missing in vbscrpt declare types of variables (unlike accessbasic/VB6)so how can i access that pointer on the other side ?
questions over questions ! i am not pretty shure if macroscheduler is the right tool for my needs but it has this really nice gimmic of picture recognition i need
regards
dj
thanks for your quick answer
i thought already about doing it in VBScript but i have 2 problems with iT:
1 is there is no debugging and very rare error information
2 is the fac was my first try to get into it what i wanna really implement is a backtraking thru a maze (wich i build up with macroscheduler finding images with FIP> and therefore i have an ARRAY GAMEFIELD[%Xi%,%Yi%]
how can i pass that to vbscript ? giving the first element as a pointer?
i also missing in vbscrpt declare types of variables (unlike accessbasic/VB6)so how can i access that pointer on the other side ?
questions over questions ! i am not pretty shure if macroscheduler is the right tool for my needs but it has this really nice gimmic of picture recognition i need
regards
dj
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
You can pass any value you like to VBScript. I'm not sure what is in your array but it can only be numbers or strings anyway. You could map that data to a corresponding VBScript array or other variables using VBEval in a loop (loop through your array and assign to VBScript variables - or create a VBScript function to grow the VBscript array and accept the values taken from your MacroScript array). Hard to say without seeing what you are doing exactly.
But sounds like you are experienced with traditional lower level programming languages. In which case why don't you use one (you seem to know VB6) and for the image recognition use the MacroScript SDK. You then have the best of both worlds and would be able to access the FindImagePos array values from within your VB6 application. See:
http://www.mjtnet.com/macroscript_sdk.htm
Macro Scheduler is a macro language, designed for automating other applications and user interfaces. It was never designed to be a low level computational tool for advanced number crunching or analytical processes (or whatever it is you want to do!).
But sounds like you are experienced with traditional lower level programming languages. In which case why don't you use one (you seem to know VB6) and for the image recognition use the MacroScript SDK. You then have the best of both worlds and would be able to access the FindImagePos array values from within your VB6 application. See:
http://www.mjtnet.com/macroscript_sdk.htm
Macro Scheduler is a macro language, designed for automating other applications and user interfaces. It was never designed to be a low level computational tool for advanced number crunching or analytical processes (or whatever it is you want to do!).
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 14
- Joined: Fri Aug 20, 2010 9:08 am
the SDK sounds great, ill try that,
what i doing is writing a scrpt that solves a game where a small fish is in a maze and u have to show him the way, sounds stupid but i just want to show thats possible
therefore i NEED interaction with this webpage (javeapplet)( getting positions via FIP but also doing mouseclicks to play the game, can i do this with the sdk , i guess i can).
here is some code i have so far tha u see what i am working on , its the part where i get the maze into an internal representation:
there are some lines commented in the code which caused in some circumstances a strange error:
[code]
'let>FE2Cmp_%FE2COMP%_X=FE2CmpX_0
'let>FE2Cmp_%FE2COMP%_Y=FE2CmpY_0
'let>FE2Cmp_%FE2COMP%_C=FE2CmpC
[/code]
the last of these 3 lines caused ( i found with the debugger) sometimes a 2=3 what had as a result that all numerical calculations where wrong, i ve seen in this case in the watchwindow the expression 2=3
Maybe you should protect numbers against overwriting ?
you can reproduce this like that:
[code]
let>2=3
let>x=2+2
mdl>2 plus 2 equal: %x%
[/code]
but here now the code of what i am doing
[code]
VBSTART
Function CBin (Number)
Dim Temp
Temp = 1
cbin="00000"
Do Until Temp > Number 'sets starting point for Len
Temp = Temp * 2
Loop
Do Until Temp = Temp Then
cbin = cbin + "1"
Number = Number - Temp
Else
cbin = cbin + "0"
End If
Temp = Temp / 2
Loop 'Loop until string is complete
End Function
VBEND
//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
let>IGNORSPACES=1
'Let>VAREXPLICIT=1
ASS>screentoproofstart,isassigned
if>%isassigned%=FALSE,setname,skipname
label>setname
let>screentoproofstart=C:\deejaysfolder\tropicana\captures\nemo_start_466427.bmp
let>screentoproofoffen=C:\deejaysfolder\tropicana\captures\nemo_offen_466427.bmp
label>skipname
'search bottom left corne of an image that is close to x0,y0
FindImagePos>C:\deejaysfolder\tropicana\nemo_find_maze_x0_y0.bmp,%screentoproofstart%,20,3,XArr,YArr,NumFound
'if we cannot find this position then we better do nothing
if>NumFound>0
let XStart=%XArr_0%+30
let YStart=%YArr_0%+30
'Alle karten aufdecken
'MouseMove>%XStart%,%XStart%
'LClick
let>y=0
repeat>y
let>x=0
repeat>x
' rand des spiels markieren, hier muessen dannn noch ein und ausgang wieder freigemacht werden
if>{(%x% = 0) OR (%y% = 0) OR (%x% = 9) OR (%y% = 7) }
let>gamefield[%x%,%y%]=0000_0000
else
'mit nichts belegen am anfang (sonderzeichen 0000 hat keine eingange ist aber verschiebbar 0100)
let>gamefield[%x%,%y%]=0000_0101
let>xy={%XStart% + ( %x% -1) *60}
let>yy={%YStart% + ( %y% -1) *60}
'MouseMove>xy,yy
' LClick
'wait>1
endif
let>x=%x%+1
Until>x>9
let>y=%y%+1
Until>y>7
' here we will find out the configuration of the actual maze
'were is start? coded as 0100_0100 (exit to the left not movable)
' we do this now in finding the first blocked part (filedelement) because that more is accurate as i found out
'FindImagePos>C:\deejaysfolder\tropicana\nemo_start.bmp,%screentoproofstart%,20,1,StartXArr,StartYArr,StartNumFound
'if>%StartNumFound%>0
' let>Xi=0
' ' why sometimes add 1 sometimes add 2 ????
' let>relposY={%StartYArr_0% - %YStart%}
' let>posY={%relposy% div 60}
' let>Yi={((%StartYArr_0% - %YStart%) div 60)+1}
' let>GAMEFIELD[%Xi%,%Yi%]=0100_0000
'endif
'find the first (blocked!) part this ist the direction were nemo will start
'there are three possiblities: 1001 1010 and 0011 so make it quick and dirty
let>i=0
repeat>i
if>i=0
let>pattern=1001_0100
else
if>i=1
let>pattern=0101_0100
else
if>i=2
let>pattern=0011_0100
endif
endif
endif
FindImagePos>C:\deejaysfolder\tropicana\nemo_fe\nemo_fe_%pattern%.bmp,%screentoproofstart%,20,1,FE2CmpX,FE2CmpY,FE2CmpC
if>%FE2CmpC%>0
let>Xi=1
let>Yi={((%FE2CmpY_0% - %YStart%) div 60)+1}
let>GAMEFIELD[%Xi%,%Yi%]=%pattern%
'eingang ins spiel setzen
if>GAMEFIELD[0,%Yi%]=0000_0100
GAMEFIELD[0,%Yi%]=0100_0100
endif
endif
add>i,1
Until>i>2
'where is the goal coded as 0001_0000 (entry from the right not movable)
FindImagePos>C:\deejaysfolder\tropicana\nemo_ziel.bmp,%screentoproofstart%,20,1,ZielXArr,ZielYArr,ZielNumFound
if>%zielNumFound%>0
let>Xi=9
'{((%ZielXArr_0% - %XStart%) div 60)+2}
let>Yi={((%ZielYArr_0% - %YStart%) div 60)+1}
let>GAMEFIELD[%Xi%,%Yi%]=0001_0100
endif
'
'now its time to search all fields we can use
'where are the deadly traps (sharks) and where are the fieldelements (streets)
'we r using a loop for k from (0000) 0101 (5) to 1100 (12) and j = 0101 to 1111 to avoid writing this code multiple times
'there r some fields(bitcombiantions not used but then Findfilepos returns -1 and we r fine with this
let>k=0
repeat>k
let>j=4
' get the bit representation
vbeval>right(Cbin(%k%),4),%FE2COMP%
if>k=0
' for the shark there is only one FT (011
let>maxj=4
else
let>maxj=15
endif
if>{(%K%=0) or (%K%=3) or (%K%=6) or (%K%=9) or (%K%=12) or (%K%=5) or (%K%=10)}
repeat>j
' get the bit representation
vbeval>right(Cbin(%j%),4),%FT2COMP%
LET>filetocompare=C:\deejaysfolder\tropicana\nemo_fe\nemo_fe_
concat>filetocompare,%FE2COMP%
concat>filetocompare,_
concat>filetocompare,%FT2COMP%
'mdl>filetocompare
FindImagePos>%filetocompare%.bmp,%screentoproofoffen%,20,1,FE2CmpX,FE2CmpY,FE2CmpC
if>FE2CmpC>0
'let>FE2Cmp_%FE2COMP%_X=FE2CmpX_0
'let>FE2Cmp_%FE2COMP%_Y=FE2CmpY_0
'let>FE2Cmp_%FE2COMP%_C=FE2CmpC
let>i=0
repeat>i
let>value=%FE2Comp%
concat>%value%,_
concat>%value%,%FT2Comp%
'mdl>FE2CmpX_%i%
let>X=FE2CmpX_%i%
let>Y=FE2CmpY_%i%
'MouseMove>%X%,%Y%
'wait>2
let>Xi={((%X% - %XStart%) div 60)+1}
let>Yi={((%Y% - %YStart%) div 60)+1}
'let>xy={%XStart% + ( %xi% -1) *60}
'let>yy={%YStart% + ( %yi% -1) *60}
' MouseMove>xy,yy
' wait>2
'when we find something in row 9 then its the changepossion which we designed on pos 9,7
if>Xi=9
let>Yi=7
endif
let>GAMEFIELD[%Xi%,%Yi%]=%value%
add>i,1
Until>i=FE2CmpC
let>LFE[%value%]=FE2CmpC
endif
add>j,1
Until>j>%maxj%
endif
add>k,1
until>k>12
endif
**BREAKPOINT**
[/code]
what i doing is writing a scrpt that solves a game where a small fish is in a maze and u have to show him the way, sounds stupid but i just want to show thats possible
therefore i NEED interaction with this webpage (javeapplet)( getting positions via FIP but also doing mouseclicks to play the game, can i do this with the sdk , i guess i can).
here is some code i have so far tha u see what i am working on , its the part where i get the maze into an internal representation:
there are some lines commented in the code which caused in some circumstances a strange error:
[code]
'let>FE2Cmp_%FE2COMP%_X=FE2CmpX_0
'let>FE2Cmp_%FE2COMP%_Y=FE2CmpY_0
'let>FE2Cmp_%FE2COMP%_C=FE2CmpC
[/code]
the last of these 3 lines caused ( i found with the debugger) sometimes a 2=3 what had as a result that all numerical calculations where wrong, i ve seen in this case in the watchwindow the expression 2=3
Maybe you should protect numbers against overwriting ?
you can reproduce this like that:
[code]
let>2=3
let>x=2+2
mdl>2 plus 2 equal: %x%
[/code]
but here now the code of what i am doing
[code]
VBSTART
Function CBin (Number)
Dim Temp
Temp = 1
cbin="00000"
Do Until Temp > Number 'sets starting point for Len
Temp = Temp * 2
Loop
Do Until Temp = Temp Then
cbin = cbin + "1"
Number = Number - Temp
Else
cbin = cbin + "0"
End If
Temp = Temp / 2
Loop 'Loop until string is complete
End Function
VBEND
//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
let>IGNORSPACES=1
'Let>VAREXPLICIT=1
ASS>screentoproofstart,isassigned
if>%isassigned%=FALSE,setname,skipname
label>setname
let>screentoproofstart=C:\deejaysfolder\tropicana\captures\nemo_start_466427.bmp
let>screentoproofoffen=C:\deejaysfolder\tropicana\captures\nemo_offen_466427.bmp
label>skipname
'search bottom left corne of an image that is close to x0,y0
FindImagePos>C:\deejaysfolder\tropicana\nemo_find_maze_x0_y0.bmp,%screentoproofstart%,20,3,XArr,YArr,NumFound
'if we cannot find this position then we better do nothing
if>NumFound>0
let XStart=%XArr_0%+30
let YStart=%YArr_0%+30
'Alle karten aufdecken
'MouseMove>%XStart%,%XStart%
'LClick
let>y=0
repeat>y
let>x=0
repeat>x
' rand des spiels markieren, hier muessen dannn noch ein und ausgang wieder freigemacht werden
if>{(%x% = 0) OR (%y% = 0) OR (%x% = 9) OR (%y% = 7) }
let>gamefield[%x%,%y%]=0000_0000
else
'mit nichts belegen am anfang (sonderzeichen 0000 hat keine eingange ist aber verschiebbar 0100)
let>gamefield[%x%,%y%]=0000_0101
let>xy={%XStart% + ( %x% -1) *60}
let>yy={%YStart% + ( %y% -1) *60}
'MouseMove>xy,yy
' LClick
'wait>1
endif
let>x=%x%+1
Until>x>9
let>y=%y%+1
Until>y>7
' here we will find out the configuration of the actual maze
'were is start? coded as 0100_0100 (exit to the left not movable)
' we do this now in finding the first blocked part (filedelement) because that more is accurate as i found out
'FindImagePos>C:\deejaysfolder\tropicana\nemo_start.bmp,%screentoproofstart%,20,1,StartXArr,StartYArr,StartNumFound
'if>%StartNumFound%>0
' let>Xi=0
' ' why sometimes add 1 sometimes add 2 ????
' let>relposY={%StartYArr_0% - %YStart%}
' let>posY={%relposy% div 60}
' let>Yi={((%StartYArr_0% - %YStart%) div 60)+1}
' let>GAMEFIELD[%Xi%,%Yi%]=0100_0000
'endif
'find the first (blocked!) part this ist the direction were nemo will start
'there are three possiblities: 1001 1010 and 0011 so make it quick and dirty
let>i=0
repeat>i
if>i=0
let>pattern=1001_0100
else
if>i=1
let>pattern=0101_0100
else
if>i=2
let>pattern=0011_0100
endif
endif
endif
FindImagePos>C:\deejaysfolder\tropicana\nemo_fe\nemo_fe_%pattern%.bmp,%screentoproofstart%,20,1,FE2CmpX,FE2CmpY,FE2CmpC
if>%FE2CmpC%>0
let>Xi=1
let>Yi={((%FE2CmpY_0% - %YStart%) div 60)+1}
let>GAMEFIELD[%Xi%,%Yi%]=%pattern%
'eingang ins spiel setzen
if>GAMEFIELD[0,%Yi%]=0000_0100
GAMEFIELD[0,%Yi%]=0100_0100
endif
endif
add>i,1
Until>i>2
'where is the goal coded as 0001_0000 (entry from the right not movable)
FindImagePos>C:\deejaysfolder\tropicana\nemo_ziel.bmp,%screentoproofstart%,20,1,ZielXArr,ZielYArr,ZielNumFound
if>%zielNumFound%>0
let>Xi=9
'{((%ZielXArr_0% - %XStart%) div 60)+2}
let>Yi={((%ZielYArr_0% - %YStart%) div 60)+1}
let>GAMEFIELD[%Xi%,%Yi%]=0001_0100
endif
'
'now its time to search all fields we can use
'where are the deadly traps (sharks) and where are the fieldelements (streets)
'we r using a loop for k from (0000) 0101 (5) to 1100 (12) and j = 0101 to 1111 to avoid writing this code multiple times
'there r some fields(bitcombiantions not used but then Findfilepos returns -1 and we r fine with this
let>k=0
repeat>k
let>j=4
' get the bit representation
vbeval>right(Cbin(%k%),4),%FE2COMP%
if>k=0
' for the shark there is only one FT (011
let>maxj=4
else
let>maxj=15
endif
if>{(%K%=0) or (%K%=3) or (%K%=6) or (%K%=9) or (%K%=12) or (%K%=5) or (%K%=10)}
repeat>j
' get the bit representation
vbeval>right(Cbin(%j%),4),%FT2COMP%
LET>filetocompare=C:\deejaysfolder\tropicana\nemo_fe\nemo_fe_
concat>filetocompare,%FE2COMP%
concat>filetocompare,_
concat>filetocompare,%FT2COMP%
'mdl>filetocompare
FindImagePos>%filetocompare%.bmp,%screentoproofoffen%,20,1,FE2CmpX,FE2CmpY,FE2CmpC
if>FE2CmpC>0
'let>FE2Cmp_%FE2COMP%_X=FE2CmpX_0
'let>FE2Cmp_%FE2COMP%_Y=FE2CmpY_0
'let>FE2Cmp_%FE2COMP%_C=FE2CmpC
let>i=0
repeat>i
let>value=%FE2Comp%
concat>%value%,_
concat>%value%,%FT2Comp%
'mdl>FE2CmpX_%i%
let>X=FE2CmpX_%i%
let>Y=FE2CmpY_%i%
'MouseMove>%X%,%Y%
'wait>2
let>Xi={((%X% - %XStart%) div 60)+1}
let>Yi={((%Y% - %YStart%) div 60)+1}
'let>xy={%XStart% + ( %xi% -1) *60}
'let>yy={%YStart% + ( %yi% -1) *60}
' MouseMove>xy,yy
' wait>2
'when we find something in row 9 then its the changepossion which we designed on pos 9,7
if>Xi=9
let>Yi=7
endif
let>GAMEFIELD[%Xi%,%Yi%]=%value%
add>i,1
Until>i=FE2CmpC
let>LFE[%value%]=FE2CmpC
endif
add>j,1
Until>j>%maxj%
endif
add>k,1
until>k>12
endif
**BREAKPOINT**
[/code]
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Yes, you can do that with the SDK.
If you have 2=3 in the watchlist then somewhere you have inadvertently created a variable called "2" and set it to the value 3.
If you have 2=3 in the watchlist then somewhere you have inadvertently created a variable called "2" and set it to the value 3.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 14
- Joined: Fri Aug 20, 2010 9:08 am
VBScript causes Error 13 (Type mismatch)
Hello Marcus it me Again
i tried to put more logig in VBscript but i fail already with ur example of fac in vbscript:
[code]
VBSTART
Dim gamefield()
Sub init_gamefield()
ReDim gamefield(9, 7,1)
End Sub
Sub set_gamefield(x, y, value1, value2)
gamefield(x, y, 0) = CStr(value1)
gamefield(x, y, 1) = CStr(value2)
End Sub
Function get_gamefield(x, y)
get_gamefield = gamefield(x, y, 0 ) + "_" + gamefield(x, y, 1 )
End Function
Function CBin (Number)
Dim Temp
Temp = 1
cbin="00000"
Do Until Temp > Number 'sets starting point for Len
Temp = Temp * 2
Loop
Do Until Temp = Temp Then
cbin = cbin + "1"
Number = Number - Temp
Else
cbin = cbin + "0"
End If
Temp = Temp / 2
Loop 'Loop until string is complete
End Function
function factorial(N)
if N = 0 then
factorial = 1
exit function
end if
factorial = N * factorial(N-1)
end function
VBEND
VBEval>factorial(5),fac
vbeval>init_gamefield,vbresult
VBEval>set_gamefield(1,1,"0000","0100"),vbresult
[/code]
VBEval>factorial(5),fac
and
VBEval>set_gamefield(1,1,"0000","0100"),vbresult
are thowing a type mismatch error when i stepp the script, the fac example is copied 1:1 from u post
there r not types declared in vbscript so i wonder if this error is from vbscript or from macroscheduler ?
regards dirk
[quote="mtettmar"]
Macro Scheduler's subroutines are just subroutines. Not functions. Functions return a result. Subroutines don't. They also can't be called inline in a calculation. They are just blocks of code you can call for convenience. Hence why you can't really do this recursively in MacroScript. You can of course use a global variable for the result. I usually prefix the variable name with the name of the subroutine to avoid confusion.
Of course you could use VBScript which DOES have functions:
VBSTART
function factorial(N)
if N = 0 then
factorial = 1
exit function
end if
factorial = N * factorial(N-1)
end function
VBEND
VBEval>factorial(5),fac[/quote]
i tried to put more logig in VBscript but i fail already with ur example of fac in vbscript:
[code]
VBSTART
Dim gamefield()
Sub init_gamefield()
ReDim gamefield(9, 7,1)
End Sub
Sub set_gamefield(x, y, value1, value2)
gamefield(x, y, 0) = CStr(value1)
gamefield(x, y, 1) = CStr(value2)
End Sub
Function get_gamefield(x, y)
get_gamefield = gamefield(x, y, 0 ) + "_" + gamefield(x, y, 1 )
End Function
Function CBin (Number)
Dim Temp
Temp = 1
cbin="00000"
Do Until Temp > Number 'sets starting point for Len
Temp = Temp * 2
Loop
Do Until Temp = Temp Then
cbin = cbin + "1"
Number = Number - Temp
Else
cbin = cbin + "0"
End If
Temp = Temp / 2
Loop 'Loop until string is complete
End Function
function factorial(N)
if N = 0 then
factorial = 1
exit function
end if
factorial = N * factorial(N-1)
end function
VBEND
VBEval>factorial(5),fac
vbeval>init_gamefield,vbresult
VBEval>set_gamefield(1,1,"0000","0100"),vbresult
[/code]
VBEval>factorial(5),fac
and
VBEval>set_gamefield(1,1,"0000","0100"),vbresult
are thowing a type mismatch error when i stepp the script, the fac example is copied 1:1 from u post
there r not types declared in vbscript so i wonder if this error is from vbscript or from macroscheduler ?
regards dirk
[quote="mtettmar"]
Macro Scheduler's subroutines are just subroutines. Not functions. Functions return a result. Subroutines don't. They also can't be called inline in a calculation. They are just blocks of code you can call for convenience. Hence why you can't really do this recursively in MacroScript. You can of course use a global variable for the result. I usually prefix the variable name with the name of the subroutine to avoid confusion.
Of course you could use VBScript which DOES have functions:
VBSTART
function factorial(N)
if N = 0 then
factorial = 1
exit function
end if
factorial = N * factorial(N-1)
end function
VBEND
VBEval>factorial(5),fac[/quote]
I ran this in 12.0.6 and it worked perfectly.
The result FAC=120 showed in the debugger window.
The result FAC=120 showed in the debugger window.
Code: Select all
VBSTART
function factorial(N)
if N = 0 then
factorial = 1
exit function
end if
factorial = N * factorial(N-1)
end function
VBEND
VBEval>factorial(5),fac
Re: VBScript causes Error 13 (Type mismatch)
Agree if returning results through the name of the function is meant here. A subroutine can also return values through it's parameters. MS is no exception here I think.djDeeJay_dot_com wrote:..............mtettmar wrote: Macro Scheduler's subroutines are just subroutines. Not functions. Functions return a result. Subroutines don't. They also can't be called inline in a calculation. They are just blocks of code you can call for convenience. Hence why you can't really do this recursively in MacroScript. You can of course use a global variable for the result. .............
Returning an array can be done by putting the name of the array 'without an index' in the gosub i.e
Call: gosub>sampleSubr,myarray
In the subr use:
%sampleSubr_VAR_1%_%index%=returnValue
see http://www.mjtnet.com/forum/viewtopic.php?t=6360
Also note that the length of the array is the largest length ever returned. So it is better to return the actual length in a second parameter separately, see next example.
And the following can be used to return a single value variable
gosub>subr,{"VarName"}
and in the subr use:
%sampleSubr_VAR_1%=returnValue
If the {} notation is not used for calling, then only the first time will result in intended return values.
I use both returns a lot, and really don't know if this way to return values is an unintended usage of the substitution power of MS.