Post subject: im new. help
Joined: 10/2/2015
Posts: 91
i was in a car accident and only have use of my right hand so i type pretty slow. i'm starting to learn lua script as i'm in college for programming and it seems fun. also, my main game is donkey kong country and tompa recommended the forums to me. so, anybody care to give me a jumpstart on lua scripting? i have the book open currently and i just got through variables, so pretty early on. any help would be greatly appreciated :)
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Joined: 10/2/2015
Posts: 91
i just need a lua script for snes9x-rr until i learn the real deal. i want a script that reads and displays one 2 byte ram value on the screeb, the game is dkc, if that helps. the ram value i want tracked is 7E0565. can someone write this basic code for me while i learn?
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Noxxa
They/Them
Moderator, Expert player (4123)
Joined: 8/14/2009
Posts: 4089
Location: The Netherlands
If you haven't seen it yet, check out the TASVideos page on lua scripting: Wiki: LuaScripting. See also this particular page for display, which is what you are asking for right now: Wiki: LuaScripting/Display But I'll give you the basic code you want right now. Try not to just blindly copy it, but try to make sure that you understand what every line of it does, so that you can make your own scripts for future purposes. Note that readword() is used to read 2-byte RAM values (a 2-byte value is referred to as a 'word' in many programming contexts).
Language: lua

local ramAddress = 0x7E0565 local ramValue while true do ramValue = memory.readword(ramAddress) gui.text(0,0, ramValue) emu.frameadvance() end
http://www.youtube.com/Noxxa <dwangoAC> This is a TAS (...). Not suitable for all audiences. May cause undesirable side-effects. May contain emulator abuse. Emulator may be abusive. This product contains glitches known to the state of California to cause egg defects. <Masterjun> I'm just a guy arranging bits in a sequence which could potentially amuse other people looking at these bits <adelikat> In Oregon Trail, I sacrificed my own family to save time. In Star trek, I killed helpless comrades in escape pods to save time. Here, I kill my allies to save time. I think I need help.
Joined: 10/2/2015
Posts: 91
i intend to scrutinize the code. that's how i learn best, through example
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Post subject: thanks again
Joined: 10/2/2015
Posts: 91
i didn't even know about the display page or drawing on the display or writing on it... i feel kinda embarrassed like i should've figure that out myself... but i DEFINITELY see the usefulness in knowing how to draw on the canvas
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Site Admin, Skilled player (1251)
Joined: 4/17/2010
Posts: 11475
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
There's also a whole bunch of scripts that go with fceux emulator. Its lua api is mostly similar to snes9x's, so you might want to check those scripts out too. Lua got me into emulator coding, so it's a valuable skill for a newcomer to gain, and it indeed starts with tweaking of others' scripts. One just needs to have access to all kinds the scripts that already exist.
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Post subject: stuck in the mud, please help.
Joined: 10/2/2015
Posts: 91
i'm having a noob issue. ive been stuck on this code for hours! can someone please help? im TRYING to understand lua code. i really am :/ while true do local keys= input.get() if (keys.Z) then local face = memory.readword(8260718) if face == 52 then memory.writeword(8261261,2000) else memory.writeword(8261261,-2000) end end emu.frameadvance() end
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Invariel
He/Him
Editor, Site Developer, Player (171)
Joined: 8/11/2011
Posts: 539
Location: Toronto, Ontario
What exactly are you trying to do besides write the value +/- 2000 to some location in memory if Z is being pressed?
I am still the wizard that did it. "On my business card, I am a corporate president. In my mind, I am a game developer. But in my heart, I am a gamer." -- Satoru Iwata <scrimpy> at least I now know where every map, energy and save room in this game is
Editor, Expert player (2329)
Joined: 5/15/2007
Posts: 3933
Location: Germany
I think you could have posted in the thread you already opened. Also, you should tell what emulator this is for because lua implementation differs sometimes.
Post subject: ohhh sorry guys!
Joined: 10/2/2015
Posts: 91
ohhh sorry guys! noob here! it's for the snes9x emu. the code is for dkc. im basically trying to make it so pressing z speeds you up. i already found the 'table' and made it so my joypad can trigger it.
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Samsara
She/They
Senior Judge, Site Admin, Expert player (2109)
Joined: 11/13/2006
Posts: 2822
Location: Northern California
Threads merged. Quick question: Why Snes9x over BizHawk/lsnes? It doesn't matter so much if all you're doing is testing things out, but if you want to submit a TAS to the site you should be using BizHawk or lsnes. Both of them have Lua functionality as well.
TASvideos Admin and acting Senior Judge 💙 Currently unable to dedicate a lot of time to the site, taking care of family. Now infrequently posting on Bluesky
warmCabin wrote:
You shouldn't need a degree in computer science to get into this hobby.
Post subject: just testing
Joined: 10/2/2015
Posts: 91
i have bizhawk, but im just testing :) i dont plan on submitting, if i do i will definitely use bizhawk
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Invariel
He/Him
Editor, Site Developer, Player (171)
Joined: 8/11/2011
Posts: 539
Location: Toronto, Ontario
If you're going to be writing code snippets in the hopes that people will help you debug, you will want to surround that code with the 'code' tag, or put your code on pastebin, so that it retains its formatting. :) And if you're going to continue writing Lua scripts for games, I would recommend using hexadecimal notation at least for your memory addresses. 0x7E0C6E is a lot easier to recognize as a memory address than 8260718.
I am still the wizard that did it. "On my business card, I am a corporate president. In my mind, I am a game developer. But in my heart, I am a gamer." -- Satoru Iwata <scrimpy> at least I now know where every map, energy and save room in this game is
Post subject: Re: stuck in the mud, please help.
Noxxa
They/Them
Moderator, Expert player (4123)
Joined: 8/14/2009
Posts: 4089
Location: The Netherlands
RainbowSprinklez wrote:
i'm having a noob issue. ive been stuck on this code for hours! can someone please help? im TRYING to understand lua code. i really am :/ while true do local keys= input.get() if (keys.Z) then local face = memory.readword(8260718) if face == 52 then memory.writeword(8261261,2000) else memory.writeword(8261261,-2000) end end emu.frameadvance() end
Why are you using decimal numbers for RAM addresses, instead of hexadecimal? It's very unintuitive, as hexadecimal numbers are used for memory addresses basically everywhere. From the looks of it, you've got your address numbers mixed up. 8261261 in hex is 0x7E0E8D. The RAM address for Donkey Kong's X speed, which I assume you're intending to change, is 0x7E0E8B. So put that in there, instead of the number you're using now. I don't know what address you're trying to use for "face" (the one you have right now is 0x7E0C6E in hex), but it doesn't look right either.
http://www.youtube.com/Noxxa <dwangoAC> This is a TAS (...). Not suitable for all audiences. May cause undesirable side-effects. May contain emulator abuse. Emulator may be abusive. This product contains glitches known to the state of California to cause egg defects. <Masterjun> I'm just a guy arranging bits in a sequence which could potentially amuse other people looking at these bits <adelikat> In Oregon Trail, I sacrificed my own family to save time. In Star trek, I killed helpless comrades in escape pods to save time. Here, I kill my allies to save time. I think I need help.
Editor, Expert player (2329)
Joined: 5/15/2007
Posts: 3933
Location: Germany
Language: Lua

--DKC v1.0 --snes9x 1.51 while true do local keys= input.get() if (keys.Z) then local face = memory.readword(0x7E0C6E) -- ? if face == 52 then memory.writeword(0x7E0E8C,2) -- speed else memory.writeword(0x7E0E8C,-2) end end emu.frameadvance() end
Change as you see fit.
Post subject: thanks guys!
Joined: 10/2/2015
Posts: 91
but its still not working as intended, although i will tweak from here. face is basically a ram value i found so when z is pressed, you accelerate in that direction. also, i am trying to get DIDDY'S x speed to change, not donkeys
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Noxxa
They/Them
Moderator, Expert player (4123)
Joined: 8/14/2009
Posts: 4089
Location: The Netherlands
In what way is it not working as intended, then? Comments like "It doesn't work" or "It's not working as intended" don't really help us understand exactly what is happening or what is supposed to happen.
http://www.youtube.com/Noxxa <dwangoAC> This is a TAS (...). Not suitable for all audiences. May cause undesirable side-effects. May contain emulator abuse. Emulator may be abusive. This product contains glitches known to the state of California to cause egg defects. <Masterjun> I'm just a guy arranging bits in a sequence which could potentially amuse other people looking at these bits <adelikat> In Oregon Trail, I sacrificed my own family to save time. In Star trek, I killed helpless comrades in escape pods to save time. Here, I kill my allies to save time. I think I need help.
Post subject: ok, im sorry
Joined: 10/2/2015
Posts: 91
makes sense. my goal is to have when diddy looks right, speed is forward. when he looks left speed is backwards. currently the way the code works, it's having donkey ONLY accelerate left and diddy ONLY accelerate right. i'm pobably wrong with my weird code, but i thought you needed a ram value to say which way you're facing. is this wrong?
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Samsara
She/They
Senior Judge, Site Admin, Expert player (2109)
Joined: 11/13/2006
Posts: 2822
Location: Northern California
I'm working backwards from BizHawk so these values might be off, but: 0x7E0C6C = Donkey's direction (50 when facing right, 114 when facing left) 0x7E0C6E = Diddy's direction (52 when facing right, 116 when facing left) Should be fairly easy to go from there, I might give it a shot myself (though I'd need to get Snes9x for that).
TASvideos Admin and acting Senior Judge 💙 Currently unable to dedicate a lot of time to the site, taking care of family. Now infrequently posting on Bluesky
warmCabin wrote:
You shouldn't need a degree in computer science to get into this hobby.
Invariel
He/Him
Editor, Site Developer, Player (171)
Joined: 8/11/2011
Posts: 539
Location: Toronto, Ontario
Note that 114 - 50 = 64 and 116 - 52 = 64. Or, more precisely:
 50 = 0011 0010  52 = 0011 0100
114 = 0111 0010 116 = 0111 0100
So, to determine facing, you just have to check if that '64' bit is on.
I am still the wizard that did it. "On my business card, I am a corporate president. In my mind, I am a game developer. But in my heart, I am a gamer." -- Satoru Iwata <scrimpy> at least I now know where every map, energy and save room in this game is
Joined: 10/2/2015
Posts: 91
thats GENIUS invariel! I never would have caught that!
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Joined: 10/2/2015
Posts: 91
I got this to sort of work. it only seems small values like 2 work. 500 DOES NOT work however. my question is, is the game somehow smart enough to not allow what i'm trying?
while true do
table = joypad.get(1)
if (table.Y) then
  local face = memory.readword(0x7E0C6E) -- ?
  if face == 52 then
    memory.writeword(0x7E0E8D,2) -- speed
    else
    memory.writeword(0x7E0E8D,-2)
  end
end
emu.frameadvance()
end
 
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Editor, Skilled player (1439)
Joined: 3/31/2010
Posts: 2108
RainbowSprinklez wrote:
I got this to sort of work. it only seems small values like 2 work. 500 DOES NOT work however. my question is, is the game somehow smart enough to not allow what i'm trying?
This is definitely possible. Games work differently from eachother, and some only allow some maximum total speed. You would have to experiment a bit and see how the game reacts. Maybe try finding the maximum value the game allows by trial and error.
Joined: 10/2/2015
Posts: 91
here is my final product. rudimentary, but it works
while true do
table = joypad.get(1)
if table.right then
	memory.writeword(0x7E0E8B,2)
  end
  if table.left then
	memory.writeword(0x7E0E8B,-2)
  end
if (table.Y) then
  if table.right then
    memory.writeword(0x7E0E8D,2000)
	memory.writeword(0x7E0E8B,3)
  end
  if table.left then
    memory.writeword(0x7E0E8D, -2000)
	memory.writeword(0x7E0E8B,-3)
  end
end
emu.frameadvance()
end
 
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Joined: 10/23/2009
Posts: 545
Location: Where?
If you do something like
[code=lua]
your code
[/code] your codes will look like mugg's post. :) Just saying.