It is currently Thu May 25, 2017 5:36 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: for next loop
Unread postPosted: Sat Mar 11, 2017 10:32 pm 
Offline

Joined: Sat Mar 11, 2017 10:25 pm
Posts: 4
Having a problem with this prog

REM Start of BASIC! Program
stt=457
playdir$ = "../../audio/3ns/"
Array.delete song$[]
File.dir playdir$, song$[]
Array.length length,song$[]
Array.shuffle song$[]
For n= stt To length step 1
Print length
Print n
tune$= playdir$+song$[n]
Print tune$
Audio.load n,tune$
Audio.stop
Audio.play n
Do
Audio.isdone isdone
Pause 1000
Until isdone
CLS
Next n

It plays the 457th mp3 and then it plays the second. I was hoping that it would play the 458th.

Please let me know what is up. :?:


Top
 Profile  
 
 Post subject: Re: for next loop
Unread postPosted: Sun Mar 12, 2017 7:20 am 
Offline

Joined: Sat Mar 11, 2017 5:49 am
Posts: 28
Hi

I think it has to do with the fact that your variable n(from the loop)
gets overwriiten by the audio.load command.
Try to use another variable there

Regards
Danny


Top
 Profile  
 
 Post subject: Re: for next loop
Unread postPosted: Sun Mar 12, 2017 9:14 am 
Offline

Joined: Sat Mar 11, 2017 10:25 pm
Posts: 4
Hi Danny, Thanx

This new code achieves the desired result.

REM Start of BASIC! Program
stt=457
playdir$ = "../../audio/3ns/"
Array.delete song$[]
File.dir playdir$, song$[]
Array.length length,song$[]
Array.shuffle song$[]
For n= stt To length step 1
Print length
Print n
tune$= playdir$+song$[n]
Print tune$
r=n
Audio.load r,tune$
Audio.stop
Audio.play r
Do
Audio.isdone isdone
Pause 1000
Until isdone
CLS
Next n

The big question is well, not being new to Basic, I have written a little in 5 or 6 flavours of Basic and did not expect this to be the issue. Is there an explanation for this (IMHO) non standard behaviour?

Thanx DavidW


Top
 Profile  
 
 Post subject: Re: for next loop
Unread postPosted: Sun Mar 12, 2017 10:43 am 
Offline

Joined: Sat Mar 11, 2017 5:49 am
Posts: 28
Hi david

Not that i am a specialist of rfobasic.
Bit i think it has to do with the fact it is an interpreted language.
I guess for every iteration it will inspect the value and see that it has changed and continue
with that changed value.
So it is a bit dangerous to change those values
The following piece of code will create a never ending loop

for i = 1 to 5
print i
i= 4
next

Regards
Danny


Top
 Profile  
 
 Post subject: Re: for next loop
Unread postPosted: Sun Mar 12, 2017 11:54 am 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 327
Hi David,
DavidW wrote:
Hi Danny, Thanx

This new code achieves the desired result.

REM Start of BASIC! Program
stt=457
playdir$ = "../../audio/3ns/"
Array.delete song$[]
File.dir playdir$, song$[]
Array.length length,song$[]
Array.shuffle song$[]
For n= stt To length step 1
Print length
Print n
tune$= playdir$+song$[n]
Print tune$

Code:
! r=n %Not needed, because Audio.load returns with r a new pointer, started with 1

If Audio.load find a defined pointer it creates not a new one.
The variable tune$ tells Audio.load about which file to load.
In other commands like BUNDLE, LIST, STACK etc. it is the same behavior.
Quote:
Audio.load r,tune$
Audio.stop
Audio.play r
Do
Audio.isdone isdone
Pause 1000
Until isdone
CLS
Next n

Code:
Audio.release r

Quote:
The big question is well, not being new to Basic, I have written a little in 5 or 6 flavours of Basic and did not expect this to be the issue. Is there an explanation for this (IMHO) non standard behaviour?

Thanx DavidW


Happy coding
Gregor


Top
 Profile  
 
 Post subject: Re: for next loop
Unread postPosted: Wed Mar 15, 2017 6:22 pm 
Offline

Joined: Sat Mar 11, 2017 10:25 pm
Posts: 4
Hi All
This is the latest that works, any comments

REM Start of BASIC! Program
stt=123
playdir$ = "../../audio/3ns/"
Array.delete song$[]
File.dir playdir$, song$[]
Array.length length,song$[]
Array.shuffle song$[]
For n= stt To length step 1
Print length
Print n
tune$= playdir$+song$[n]
Print tune$
t=1
Audio.load t,tune$
Audio.stop
Audio.play t
Do
Audio.isdone isdone
Pause 1000
Until isdone
Audio.stop
Audio.release t
CLS
Next n


It is to be noted that Audio.load 1,tune$ threw an error while Audio.load t,tune$ worked fine
Thanx All

DavidW


Top
 Profile  
 
 Post subject: Re: for next loop
Unread postPosted: Wed Mar 15, 2017 6:43 pm 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 327
Hi David,
DavidW wrote:
t=1

t=1 is obsolete, because Audio.load creates a new one if necessary.
Quote:
It is to be noted that Audio.load 1,tune$ threw an error while Audio.load t,tune$ worked fine

The first parameter at Audio.load must be a variable.

/Gregor


Top
 Profile  
 
 Post subject: Re: for next loop
Unread postPosted: Wed Mar 15, 2017 8:34 pm 
Offline

Joined: Sat Mar 11, 2017 10:25 pm
Posts: 4
Hi All
This was not an issue with the for next loop but a misunderstanding about how Audio.load works. Thanx Gregor and Danny for your patient help.

Thanx DavidW


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred