
-----------------------------------
Kalimoor
Wed Jan 09, 2019 9:02 pm

Procedure parameter in build-in function (such as GUI.CreateButton)
-----------------------------------
Hi Turing experts,

Suppose I have the below button created, what I am trying to do is to insert a parameter to playMusic procedure,

button := GUI.CreateButton(fileButtonPositionX, fileButtonPositionY-25, 0, "Play", playMusic(current_file))

Below is my procedure,

procedure playMusic (filename: string)
    locate(1, 1)
    fork BackgroundMusic(filename)
end playMusic

As you can see, I need to input the current_file, which is a string, to playMusic procedure and then the process BackgroundMusic will take the music current_file and play it.

However, when I did it, it keeps on saying "playMusic is a procedure call and hence does not return a value". I looked online all over the place but I never found an information that process can take a parameter inside CreateButton.

Please help me out here! Thank you!!

-----------------------------------
Insectoid
Wed Jan 09, 2019 9:59 pm

RE:Procedure parameter in build-in function (such as GUI.CreateButton)
-----------------------------------
Do you have any other calls to playMusic elsewhere in the code? 

The only thing I can think of is that *maybe* Turing won't allow procedures with parameters to be an actionproc (the procedure called by a button).

Somewhere in the code it's asking playMusic for a result as if it were a function.

-----------------------------------
Kalimoor
Wed Jan 09, 2019 10:15 pm

Re: RE:Procedure parameter in build-in function (such as GUI.CreateButton)
-----------------------------------
Do you have any other calls to playMusic elsewhere in the code? 

The only thing I can think of is that *maybe* Turing won't allow procedures with parameters to be an actionproc (the procedure called by a button).

Somewhere in the code it's asking playMusic for a result as if it were a function.


Hi Sir,

Sorry I had to delete my code because it is for an assignment. If possible, can you demonstrate to me how I can pass a parameter to a procedure used by CreateButton?

Thanks!

-----------------------------------
Insectoid
Thu Jan 10, 2019 11:45 am

RE:Procedure parameter in build-in function (such as GUI.CreateButton)
-----------------------------------
The simplest answer is to use declare current_file globally, and accessing it directly from playMusic()


Var current_file

Proc playMusic 
    Fork backgroundMusic (current_file)
End playMusic

It's not really good practise, but if it works it works. Turing does have a few strange issues related to the GUI, this may be one of them. I don't ever use it myself, I prefer making my own buttons with Mouse.Where and draw commands.

-----------------------------------
Kalimoor
Thu Jan 10, 2019 7:15 pm

Re: RE:Procedure parameter in build-in function (such as GUI.CreateButton)
-----------------------------------
The simplest answer is to use declare current_file globally, and accessing it directly from playMusic()


Var current_file

Proc playMusic 
    Fork backgroundMusic (current_file)
End playMusic

It's not really good practise, but if it works it works. Turing does have a few strange issues related to the GUI, this may be one of them. I don't ever use it myself, I prefer making my own buttons with Mouse.Where and draw commands.

Yes, but what if I need to search for all the music files in the folder but I don't know how many music files there are in the folder? After I select the right file, I need to play it. What you did there is static, I can only have 1 music file by current_file, but I need to change the file and play the music, how would I accomplish that?

-----------------------------------
Nomalah
Fri Jan 11, 2019 7:14 am

Re: Procedure parameter in build-in function (such as GUI.CreateButton)
-----------------------------------
Before you call the procedure just update the value of the variable.
[code]
import GUI
var musicfile:string

process play_current_music(Music_file_tobe_used:string)
Music.PlayFile(Music_file_tobe_used)
end play_current_music

proc playmusic
fork play_current_music(musicfile)
end proc


loop
if correct music then
musicfile:= ChosenFile
end if
end loop


var button : int :=GUI.CreateButton(10,10,50,"hello",playmusic)

loop
exit when GUI.ProcessEvent
end loop


[/code]
