Procedure parameter in build-in function (such as GUI.CreateButton)
Author |
Message |
Kalimoor
|
Posted: Wed Jan 09, 2019 9:02 pm Post subject: 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!! |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Insectoid

|
Posted: Wed Jan 09, 2019 9:59 pm Post subject: 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
|
Posted: Wed Jan 09, 2019 10:15 pm Post subject: Re: RE:Procedure parameter in build-in function (such as GUI.CreateButton) |
|
|
Insectoid @ Wed Jan 09, 2019 9:59 pm wrote: 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

|
Posted: Thu Jan 10, 2019 11:45 am Post subject: 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
|
Posted: Thu Jan 10, 2019 7:15 pm Post subject: Re: RE:Procedure parameter in build-in function (such as GUI.CreateButton) |
|
|
Insectoid @ Thu Jan 10, 2019 11:45 am wrote: 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
|
Posted: Fri Jan 11, 2019 7:14 am Post subject: 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
|
|
|
|
|
|
 |
|
|