プレイ日記
Thompson tom_mai78101
How to pass an array to a DEF function?
2そうだね
プレイ済み
返信[1]
親投稿
Perska Perska02
You can pass an array as a regular parameter. DIM MYARRAY[2] MYARRAY[0]=9 MYARRAY[1]=15 PRINR ARRFUNC(MYARRAY) DEF ARRFUNC(ARRAY) FOR I%=0 TO LEN(ARRAY)-1 INC RETURNS, ARRAY[I%] NEXT RETURN RETURNS END If everthing went well, you should see 24 in the console
0そうだね
プレイ済み
返信[2]
親投稿
Thompson tom_mai78101
Wait. That means I need to use a Percent symbol? And how exactly do I pass an array element? Thanks though.
0そうだね
プレイ済み
返信[3]
親投稿
Zee Storybookten9
No, the % is an integer suffix. You can still use doubles. You can pass array elements exactly the same as literals. DIM ARR[1] ARR[0]=7 MAIN(ARR[0]) Works the same as MAIN(7)
0そうだね
プレイ済み
返信[4]
親投稿
Thompson tom_mai78101
Oh ok. Thanks for clarifying the Percent symbol. But why is this an illegal call? (See screenshot.) I am just passing an array as a parameter.
0そうだね
プレイ済み
返信[5]
親投稿
Perska Perska02
The function has no return values. To make a function with no returns, use the following syntax: DEF FUNCNAME [PARAMS1,...] DEF MYCMD HI$, COUNT PRINT HI$*COUNT 'prints the given string COUNT times END You get the gist. Check the help for DEF for more info.
0そうだね
プレイ済み
返信[6]
親投稿
Perska Perska02
One more thing: just "MAIN(ARRAY)" won't work even if it returned something.
0そうだね
プレイ済み
返信[7]
親投稿
Thompson tom_mai78101
This is conflicting. DEF doesn't mention about passing arrays in the reference list, unless I read it wrong. If I can pass arrays, but I am doing something wrong in the screenshot in the above post, then it has to be the function parameters. I have to pass a size of the array? And this applies to all functions passing arrays? Besides, I didn't see how to pass multiple arrays as function parameter
0そうだね
プレイ済み
返信[8]
親投稿
Thompson tom_mai78101
And may I ask what did you mean by "Just MAIN(T) won't work, even if it returned nothing."? This comment is confusing to me.
0そうだね
プレイ済み
返信[9]
親投稿
Zee Storybookten9
If it did return something, you need to set something to that value or use that value. However, since it does not, you need to omit the parenthesis. DEF MAIN T Instead of DEF MAIN(T). That would work.
0そうだね
プレイ済み
返信[10]
親投稿
Thompson tom_mai78101
Oh I see. Parentheses do make a difference. Thanks for the info!
0そうだね
プレイ済み
返信[11]
親投稿
Thompson tom_mai78101
I am keeping this sample code here as reference for future me. Includes number to string conversion.
0そうだね
プレイ済み