Lua not working

Sailor Muffin

Always changing my PFP
Heya
I tried to do a lua to make Sonic slide when pressing C2

addHook("ThinkFrame", function()
local player = "sonic"
if player.mo and player.mo.valid and not player.invincible then
if player.cmd.buttons & BT_CUSTOM2 > 0 then
if not player.mo.sliding then
if player.mo.state ~= S_PLAY_DEAD then
player.mo.state = S_PLAY_STND
end
player.mo.sliding = true
end
else
player.mo.sliding = false
end
end
end)

But it doenst work
And i get no errors when loading it in game
 
You tried to have chatGPT write this? I don't know why you'd think SRB2 would know you're referring to a player with a "sonic' string.

player.invincible is not a vanilla variable, and shouldn't be relevant to your sliding ability. Only an AI would make those mistakes.

addHook("PlayerThink", function(player)
if player.mo
if (player.cmd.buttons & BT_CUSTOM2)
if not player.mo.sliding
if player.mo.state ~= S_PLAY_DEAD
player.mo.state = S_PLAY_STND
end
player.mo.sliding = true
print("This is where I'd slide if I had code defining what sliding was! But hey, I can confirm player.mo.sliding is true!")
end
elseif player.mo.sliding
player.mo.sliding = false
print("This is where I'd stop sliding! I can confirm player.mo.sliding has been set from true to false now!")
end
end
end)

First, use a PlayerThink hook, that way you already have "player" defined by default. Then, forget about player.invincible entirely. Now it'll actually affect the player, but the behavior itself still isn't programmed, you only made a way to toggle "player.mo.sliding".

It's not "wrong" to use AI. Most of the time, AI can write properly sorted Lua code that won't error. But doesn't mean the code will accomplish anything. Because SRB2 doesn't know to make Sonic backflip over Eggman's head and snap his neck just because you gave him player.mo.BackFlipsOverEggmanAndSnapsHisNeck. So if you're using an AI as a base, verify EVERYTHING it writes and what actually exists, because AI has extremely limited knowledge on SRB2 specifics.

For example, you can see what variables exist by googling "SRB2 Lua Userdata". You can find out what hooks are proper to use by googling "SRB2 Lua Hooks". You can find out what states exist by looking up "SRB2 states list". You could discover SRB2's standard Lua functions googling "SRB2 lua functions". Etc!

Even if you don't know coding, if you keep looking things up and verifying what the AI writes, you can modify its nonsense into something actually usable and make something cool eventually.
 
Yes,i used chatgpt in the hopes of getting something that i could fix
And i have a small idea of how lua works
Then i somehow tried to fix

But thanks!
I might use the one that you made as base for making luas!
 
Last edited:

Who is viewing this thread (Total: 0, Members: 0, Guests: 0)

Back
Top