Code: Select all
get_oauth() {
static oauth := 0
if !oauth {
fo := FileOpen(a_scriptdir "\oauth", 0)
oauth := fo ? fo.read() : 0
}
return oauth
}
Code: Select all
get_oauth() {
static oauth := 0
if !oauth {
fo := FileOpen(a_scriptdir "\oauth", 0)
oauth := fo ? fo.read() : 0
}
return oauth
}
Code: Select all
#warn
Loop
MsgBox, % get_oauth()
get_oauth() {
static oauth := 0
if !oauth {
fo := FileOpen(a_scriptdir "\oauth", 0)
oauth := fo ? fo.read() : 0
ToolTip, % A_TickCount
}
return oauth
}
Duh thank you... did not occur to me this order would matter. Also the warn dialog is kind of vague in this context,lexikos wrote:If you are calling the function (directly or indirectly) from a static initialiser, check the order of the static initialisers in your script.
Code: Select all
; read oauth from file
lib_oauth() {
static oauth := 0
if !oauth
; read oauth
return oauth
}
; requires authentication + clientID
lib_REST_command() {
static oauth := lib_oauth(), clientID := lib_clientID()
; send command
return response
}
; also requires authentication
lib_clientID() {
static oauth := lib_oauth(), clientID := 0
if !clientID
; get clientID
return clientID
}
When I run the excerpt you posted, it warns about clientID.In this order, warn always points to the var oauth in lib_clientID,
I explained it wrong, not the initializing var being pointed at but a later evaluation which fails -lexikos wrote:When I run the excerpt you posted, it warns about clientID.
Code: Select all
; read oauth from file
lib_oauth() {
static oauth := 0
if !oauth
; read oauth
return oauth
}
; requires authentication + clientID
lib_REST_command() {
static oauth := lib_oauth(), clientID := lib_clientID()
; send command
return response
}
; also requires authentication
lib_clientID() {
static oauth := lib_oauth(), clientID := 0
if !oauth ; <-- warn points to this line/reference, oauth undefined
return "error"
if !clientID
; get clientID
return clientID
}
more than one interface depends on this token/client, I want these functions to be callable elsewhere for now.kczx3 wrote:Why not use a class for this?
Users browsing this forum: Bing [Bot], peter_ahk and 167 guests