Advertisement
feasel

General LUA Tips

Mar 19th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. LUA is pretty easy to learn compared to many languages. A couple gotchas:
  2. * The code will not execute if the emulator is paused.
  3. * Make sure your program's main loop calls emu.frameadvance() every time or else nothing will work and the emulator won't accept keyboard or controller input.
  4. * All variables (except the counters for for-loops and the formal parameters of functions) are global by default. Every time you want to create a new variable inside a function make sure you declare it as "local".
  5. * LUA is pretty loosely syntax-checked. So be careful of typos in variable names, because you won't hear any errors about them until the first time that line of code is executed. And if the typo happens to be on the left side of an assignment, you will not hear about the error at all, and the malfunction will be difficult to track down.
  6. * The top 8 pixel rows of the screen can not be drawn to -- they are outside the frame of what the emulator window shows.
  7. * Arrays are 1-based indexing (except for x,y coordinates on the screen, which are 0-based)
  8. * The start and end values of for-loops are INCLUSIVE, so "for i = 1,4 do" would execute 4 times.
  9. * The start, end, and increment values of for-loops are computed only once when the for-loop is first entered. Unlike C++ and Java where the end condition and the increment expression are re-evaluated upon every iteration. So in LUA something like "for i = 1,areWeThereYet() do" would only call the function areWeThereYet() a single time, whereas the equivalent for loop in C++ would call areWeThereYet() on every iteration.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement