Quote: "I am having a tiny problem with my code."
Quote: "
do
if Upkey()=1 then move object 1,5
if Downkey()=1 then move object 1,-5
if Leftkey()=1 then Yrotate object 1,wrapvalue(A1Y#-3.5)
if Rightkey()=1 then Yrotate object 1,wrapvalue(A1Y#+3.5)
sync
loop
if inkey$() <> "s" then gosub cube2
cube2:
do
if Upkey()=1 then move object 2,5
if Downkey()=1 then move object 2,-5
if Leftkey()=1 then Yrotate object 2,wrapvalue(A1Y#-3.5)
if Rightkey()=1 then Yrotate object 2,wrapvalue(A1Y#+3.5)
sync
loop
wait key
"
Okay, OP, you have some solutions but you need to understand
why your code doesn't work so we'll go through this.
Firstly, you've a DO..LOOP with a set of instructions. Fine. But your condition for switching cubes is
outside the DO..LOOP so essentially you'll keep looping and never reach that
IF INKEY$() = "s" part. Secondly, and this wouldn't be apparent straight away be you are calling GOSUB above your label. This is pointless because the program executes from top to bottom, meaning it'll go to your label anyway. This method of using a label is wrong however, as Phaelax pointed out, for the reasons he stated (as well as the fact that GOTO/GOSUB should be avoided by newcomers).
@Phaelax:
I think you made a typo:
Quote: "
if inkey$() <> "s" and vkFlag = 0
vkFlag = 1
inc obj_id
if obj_id > 3 then obj_id = 1
endif
"
You said if inkey$() != 's'... should be ==. I do that too and then the next day I'm like "why won't it work!?" when I compile, lol
My most recent blunder was yesterday evening when I was comparing to string buffers and I had = instead of ==. I read over the code about 5 times and didn't spot it till I ran through it outputting the results for every line. The minute I saw the assignment pop up on screen I thought "Noooo, I checked the code!"
Also, forgot to update the "A1Y#" variable at the end of the controls codeblock.
Just gonna post the corrected code for OP's education:
obj_id = 1
sync on
sync rate 60
do
if Upkey()=1 then move object obj_id,5
if Downkey()=1 then move object obj_id,-5
if Leftkey()=1 then Yrotate object obj_id,wrapvalue(A1Y#-3.5)
if Rightkey()=1 then Yrotate object obj_id,wrapvalue(A1Y#+3.5)
A1Y# = OBJECT ANGLE Y(obj_id) // Here
if inkey$() = "s" and vkFlag = 0 // And here
vkFlag = 1
inc obj_id
if obj_id > 3 then obj_id = 1
endif
if inkey$() = "" then vkFlag = 0
sync
loop
Anyway, OP, hope this is of use.