View previous topic :: View next topic |
Author |
Message |
ZacTheSin I post too much Reputation: 6
Joined: 09 May 2006 Posts: 2657
|
Posted: Sun Apr 12, 2015 3:38 am Post subject: Variable disappearing after function end |
|
|
After the first time, which seems to run fine - the script seems to never pick up that windowPreviousInteger has been created as a variable down the line.
Do I need to be defining it before the script starts (which would kind of defeat the purpose of the script in the first place)
Also, I do understand that this needs some major rewriting, which I plan on doing once I know that the variables are actually being seen.
Code: |
function loadWindow() -- Window selection (executing function after first time connects gameWindow variable to find_window_match('Fushbot' .. windowPreviousInteger) - or it should)
if(windowPreviousInteger == nil) then
print('New Instance found')
windowSharedInteger = allocateSharedMemory("windowInteger", 4096)
gameWindow = winapi.find_window_match('game')
if(windowSharedInteger == nil) then
print('First instance found - creating windowSharedInteger')
writeInteger(windowSharedInteger, 1)
gameWindow:set_text('FushBot' .. readInteger(windowSharedInteger))
gameWindow = winapi.find_window_match('FushBot' .. readInteger(windowSharedInteger))
windowPreviousInteger = 0
writeInteger(windowPreviousInteger, 1)
print('windowPreviousInteger set as 1')
else
print('Connecting to client ' .. readInteger(windowSharedInteger) .. ', like a boa5.')
writeInteger(windowSharedInteger, (readInteger(windowSharedInteger)+1))
gameWindow:set_text('FushBot' .. readInteger(windowSharedInteger))
gameWindow = winapi.find_window_match('FushBot' .. readInteger(windowSharedInteger))
writeInteger(windowPreviousInteger, readInteger(windowSharedInteger))
windowPreviousInteger = readInteger(windowPreviousInteger) -- Tried this to see if that would fix the creation of the variable - it should be global right?
end
else
print('Existing client found, connecting to client ' .. readInteger(windowPreviousInteger))
gameWindow = winapi.find_window_match('FushBot' .. readInteger(windowPreviousInteger))
end
end
|
_________________
If someone helps you, why not Rep them? |
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25287 Location: The netherlands
|
Posted: Sun Apr 12, 2015 6:23 am Post subject: |
|
|
Code: |
windowPreviousInteger = readInteger(windowPreviousInteger)
|
only gets executed when windowPreviousInteger is nil
when readInteger fails, it returns nil
also, windowSharedInteger should never be nil
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
ZacTheSin I post too much Reputation: 6
Joined: 09 May 2006 Posts: 2657
|
Posted: Sun Apr 12, 2015 8:08 am Post subject: |
|
|
Thanks DB, you the real MVP.
I ended up rewriting it and came out with this:
Code: | function windowSelect(fushBotSessionInt)
if(fushBotSessionInt == 0) then
print('New FushBot session') -- no previous Fushbot session found
windowSharedInteger = allocateSharedMemory("windowInteger", 4096)
gameWindow = winapi.find_window_match('game')
if (windowSharedInteger == 0) then
print('First instance found - creating windowSharedInteger')
writeInteger(windowSharedInteger, 1)
local gameWindowName = 'FushBot' .. readInteger(windowSharedInteger)
gameWindow:set_text(gameWindowName)
gameWindow = winapi.find_window_match(gameWindowName)
print('fushBotSession:\t', readInteger(windowSharedInteger))
return(readInteger(windowSharedInteger))
elseif (windowSharedInteger > 0) then
writeInteger(windowSharedInteger, (readInteger(windowSharedInteger)+1))
local gameWindowName = 'FushBot' .. readInteger(windowSharedInteger)
gameWindow:set_text(gameWindowName)
gameWindow = winapi.find_window_match(gameWindowName)
return(readInteger(windowSharedInteger))
else
print("Failed to find game client to connect new Fushbot session")
end
elseif(fushBotSessionInt > 0) then
print('Existing Fushbot session found -- connecting ' .. fushBotSessionInt)
gameWindow = winapi.find_window_match('FushBot' .. fushBotSessionInt)
return fushBotSessionInt
else
print('No session found? Exiting.')
return nil
end
end |
sitting inside of:
Code: | if(fushBotSession == nil) or (fushBotSession == 0) then
fushBotSession = windowSelect(0)
elseif(fushBotSession > 0) then
fushBotSession = windowSelect(fushBotSession)
end |
Which flows on from the scriptRun() function.
_________________
If someone helps you, why not Rep them? |
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25287 Location: The netherlands
|
Posted: Sun Apr 12, 2015 9:28 am Post subject: |
|
|
what i meant with "also, windowSharedInteger should never be nil" is that allocateSharedMemory("windowInteger", 4096) never fails (assuming it's attached to a process) it will always allocate a block referencing that shared memory block (creating it when neededl
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
|