Thread question (call procedure)

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by cor.

I have the following code:

call the checkcommand() from the thread doesn't work.
It doesn't fire up.

What am I doing wrong?

Code: Select all

 
CreateThread(@ScanKeysThread(), 100)
;
;
Procedure ScanKeysThread()
com$=""
Repeat
  c=GetKey() ; Pause app until a key has been pressed.
  If c  32 ; space pressed
   com$=com$+Chr(c)
   Else
    MessageRequester("",com$,0)   ; This works
    checkcommand() ; this doesn't work
    com$=""
  EndIf
Until ForEver ; Loop forver
EndProcedure
;
Procedure checkcommand()
  MessageRequester("",com$,0)
EndProcedure
Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

Try changing the order of your routines so that each section is referencing
something that has been declared. At the moment, the thread is calling a
procedure that hasn't been declared yet, which is probably the problem.
I say "probably" because I'm not 100% sure as I don't use threads yet.

So, change your code to this:

Code: Select all

; Declare this procedure first so ScanKeysThread knows about it.
Procedure checkcommand()
  MessageRequester("",com$,0)
EndProcedure
;
Procedure ScanKeysThread()
com$=""
Repeat
  c=GetKey() ; Pause app until a key has been pressed.
  If c  32 ; space pressed
   com$=com$+Chr(c)
   Else
    MessageRequester("",com$,0)   ; This works
    checkcommand() ; this doesn't work
    com$=""
  EndIf
ForEver ; *** Changed from "Until ForEver" because "Until" isn't needed ***
EndProcedure
;
; Do this last so it knows about the ScanKeysThread procedure.
CreateThread(@ScanKeysThread(), 100)

PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by cor.

Order of procedures doesn't matter.

All procedures are declared.

Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Your variable isnt SHARED...

Code: Select all

Procedure checkcommand()
Shared com$
  MessageRequester("",com$,0)
EndProcedure
 
 
Procedure ScanKeysThread()
Shared com$
com$ = "TEST"
    checkcommand() ; this doesn't work
EndProcedure
 
 
CreateThread(@ScanKeysThread(), 100)
 
Delay(10000)
cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Your variable isnt SHARED...

That wouldn't matter though... the MessageRequester would just show an empty
string. Cor, do you mean that the MessageRequester is never showing up in
the CheckCommand() procedure? That's what I understand the problem to be?


PB - Registered PureBasic Coder
Post Reply