tommy asked in Society & CultureLanguages · 2 months ago

Can someone tell me what this specific Lua script means.?

function AOBRep(search, change)

    local aob = AOBScan(search)

    if aob then

      for i=0,aob.Count-1 do

        autoAssemble(aob[i]..':\ndb '..change)

      end

      aob.Destroy()

    end

    end

Please explain what this means. And really dumb it down for me because I am new to this. Thanks.

1 Answer

Relevance
  • 2 months ago

    Okay, so most of this code is understandable for me except for two parts: The functions for autoAssemble and AOBScan. A quick Google on the latter told me this:

    AOBScan is a function typically used in Cheat Engine, though it might exist elsewhere. It scans the memory of the computer for the data you put in.

    So it takes the result from AOBScan and sticks it in a variable (think bookmark) called "aob".

    The next line (if aob then) only runs if aob exists, or if the search returned true. I'm not familiar with this code, so I can't say for sure. I'll assume it means "if it exists, run the stuff inside the if statement". Pretty simple.

    Here's where things get interesting.

    The next line, "for i=0,aob.Count-1 do" needs some breaking down.

    First, we have "for", meaning to create a loop. Because it's a "for" type loop, it will increase a counter by 1 every time it runs. In this case, the counter is "i". We set this to zero and whenever the loop runs it increases by one.

    I can't explain the index system very well, but here we go.

    If I want to store the names of my friends in an array (very similar to what Lua is using here) it would look something like this: array = ["Alice","Bob",Charles"]. If I want Alice, I say this: array[0]. So, the 0th item is actually the first item we see. Not too hard once you're used to it, but it can throw a lot of newbie coders for a loop.

    Now, the reason all of that is relevant is because aob.Count counts the number of items in the list. So where array[2] from the previous example is "Charles" here, there's actually 3 elements. That's why it uses "Count-1". It means that it won't try to edit something that doesn't exist.

    I don't have a clue about autoAssemble, but the rest of the code so far implies that the function will change the memory (think binary or hexadecimal). So, it might change the data "8A 5F 1D F9 00 A1" to "8B 1A 3D F9 01 A0". It can only do one at a time, though (e.g: 8A -> 8B) so that's why there's a loop.

    The rest is pretty easy. The first "end" tells the loop that that's the end. Once the code sees this, it'll jump back to the top of the "for" loop and check if i is less than Count-1.

    aob.Destroy() cleans up the memory used by deleting the memory we created earlier. Remember, this only runs if aob matched (we're still inside the if statement), so there's no worry about aob not existing when we run the command.

    The final 2 "end" commands are for exiting the if statement, and then for exiting the function. That way, all the code is contained inside the function (and it doesn't run into other ones. That would be bad!)

    I hope this helped! This is a throwaway account since I lost my main one, so I probably won't be able to reply. Sorry about that!

    Source(s): Passed my Computer Science A-Level, and am working to become a professional
Still have questions? Get your answers by asking now.