# WHY?

0

japanese 2020-08-18 23:24

Why score is increasing?
Because SCORE1 and SCORE2 are forever 0
What I’m trying to say is 0+1=1 next time 0+1=1 …
Sorry it's hard to understand.
Please tell me who understands :)

2020-08-18 23:24

qwaffe 2020-08-19 05:28

when you pass a variable as an argument it only passes its value into the subprogram. the S variable in the subprogram ends up being local to only the subprogram and doesn't really set the variable you passed as argument (SCORE1).

moechofe 2020-08-19 05:36

@qwaffe, that is not true in LowresNX Basic. When you pass a variable as sub program argument, it do pass as a reference, even if it's an array element.

qwaffe 2020-08-19 06:07

oh, my bad. i had assumed itd be the same here as with some of the languages i know, but i was wrong. geuss i learned something today

moechofe 2020-08-19 07:17

and it also provide a lot of possibilities. you can “actually” make sub routine “return” values.

japanese 2020-08-19 10:24

i can't understand why score is increasing
Could you explain that more simply?

moechofe 2020-08-19 10:32

yes!

In this line: SCORE(SCORE1,1,0)
You pass 3 arguments: score1, 1 and 0
- The second and third are passed by values
- The first is passed as reference

In the definition of the sub routine: SUB SCORE(S,DS,X)
You asking for 3 parameters: S, DS and Y
- As we saw above the second and third are passed by values so, the DS and Y variable actually contain the number 1 and 0 respectivly
- For the first: because it was passed as reference, the variable S contains a reference to SCORE1. If you change the S variable, you'll will also change the SCORE1 variable.

To fix it, you need to copy the variable in the sub routine:
SUB SCORE(S,DS,X)
SCOPY=S+DS
NUMBER X,0,SCOPY,2
END SUB

japanese 2020-08-19 11:21

i got it!
Your explanation is very easy to understand.
thank you very much! :)