Jump to content
  • 0

How to edit select values in a search?


uraveragedude
 Share

Question

So, I'm a newbie to LUA scripting for GameGuardian, and I was just creating a simple Magic Bullets script so I didn't have to manually search the values. The thing is, with the values that i have to edit, I need to edit all of them except for just one. I was wondering how to do that, and yes, I have already tried gg.targetResultsNumbers. Please help!

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

Could you give an example? Sorry, I do not currently know all of the API as I have just started on GameGuardian LUA scripts.

Here is my code:

gg.searchNumber('2', gg.TYPE_FLOAT)

gg.getResults(22)

print('Replaced: ', gg.editAll('-2', gg.TYPE_FLOAT))

gg.toast(Magic Bullets activated!)

Link to comment
Share on other sites

  • 0
52 minutes ago, uraveragedude said:

Could you give an example?

You need to know how to find the result that you want to be excluded from editing. Most likely, it's position in result list won't be consistent.

Here is an example of implementing the algorithm described by Enyby:

gg.searchNumber('2', gg.TYPE_FLOAT)
local results = gg.getResults(22)
local excludedResultNumber = 4
if results[excludedResultNumber] ~= nil then
  results[excludedResultNumber] = nil
end
for k, v in pairs(results) do
  v.value = '-2'
end
print('setValues: ', gg.setValues(results))

You will need to adapt it according to your requirements.

Link to comment
Share on other sites

  • 0

Another example that may be easier to understand (since it uses "editAll" function, which is used very often by novice script-writers):

gg.searchNumber('2', gg.TYPE_FLOAT)
local results = gg.getResults(22)
local excludedResultNumber = 4
if results[excludedResultNumber] ~= nil then
  gg.removeResults({results[excludedResultNumber]})
end
print('editAll:', gg.editAll('-2', gg.TYPE_FLOAT))

This approach consists of 2 main steps:

  1. The result that should not be changed is removed from the list of results.
  2. "editAll" function is applied to edit all results that remained in the list.
Edited by CmP
Link to comment
Share on other sites

  • 0

After adding the changes you suggested CmP, I get this error:

Script ended:

Script error: org.luaj.vm2.LuaError: load /storage/emulated/0/Download/gg scripts/demo.lua: org.luaj.vm2.LuaError: /storage/emulated/0/Download/gg scripts/demo.lua:45

`print('You did not select anything')`

<goto noselect> at line 19 jumps into the scope of local 'results'

at org.luaj.vm2.LuaValue.error(LuaValue.java:1076)

at org.luaj.vm2.Globals.loadfile(Globals.java:230)

at android.ext.Script.runScript(Script.java:4492)

at android.ext.Script$ScriptThread.run(Script.java:4326)

Caused by: org.luaj.vm2.LuaError: /storage/emulated/0/Download/gg scripts/demo.lua:45

`print('You did not select anything')`

<goto noselect> at line 19 jumps into the scope of local 'results'

at org.luaj.vm2.compiler.LexState.lexerror(LexState.java:278)

at org.luaj.vm2.compiler.LexState.syntaxerror(LexState.java:282)

at org.luaj.vm2.compiler.LexState.semerror(LexState.java:840)

at org.luaj.vm2.compiler.LexState.closegoto(LexState.java:991)

at org.luaj.vm2.compiler.LexState.findgotos(LexState.java:1036)

at org.luaj.vm2.compiler.LexState.labelstat(LexState.java:1772)

at org.luaj.vm2.compiler.LexState.statement(LexState.java:2114)

at org.luaj.vm2.compiler.LexState.statlist(LexState.java:2145)

at org.luaj.vm2.compiler.LexState.mainfunc(LexState.java:2161)

at org.luaj.vm2.compiler.LuaC$CompileState.luaY_parser(LuaC.java:129)

at org.luaj.vm2.compiler.LuaC.compile(LuaC.java:99)

at org.luaj.vm2.Globals.compilePrototype(Globals.java:349)

at org.luaj.vm2.Globals.loadPrototype(Globals.java:328)

at org.luaj.vm2.Globals.load(Globals.java:299)

at org.luaj.vm2.Globals.loadfile(Globals.java:224)

... 2 more

I was confused, as after I changed the code, this popped up when it didn't happen before. Was it a problem with my noselect? Here is what I had down:

if menu == nil then print('error') end

goto noselect

Sorry to be a bother!

Edited by uraveragedude
Link to comment
Share on other sites

  • 0
17 minutes ago, uraveragedude said:

After adding the changes you suggested CmP, I get this error:

I would suggest not using "goto" at all, but it's up to you.

One thing you can try is "converting" all parts of the code that starts with labels to functions and replacing all goto usages with the calls to corresponding functions.
Another option is to change all local variables to global (so that goto jumps won't enter local variables scope), but this is awful solution that is considered to be bad practice.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.