Lua issues from a newbie

Status
Not open for further replies.

Yacker

Metallic
I'm new to Lua of course and most of my knowledge comes from looking at the wiki, and other scripts, but I can't figure out what is wrong with my script, no matter how hard I try. Can anyone identify the issue?
Code:
addHook("ThinkFrame", do
for player in players.iterate
	if player.reset == false
		player.customtimer = 0
		player.reset = true
	end
end
end)

addHook("MobjThinker", function(player)
	if player.state == S_PLAY_STND then
		player.customtimer = player.customtimer + 1
		if player.customtimer < 13 then
			player.frame = U
		end
		if player.customtimer > 12 and player.customtimer < 15 then
			player.frame = U
		end
		if player.customtimer > 14 and player.customtimer < 27 then
			player.frame = V
		end
		if player.customtimer > 26 and player.customtimer < 29 then
			player.frame = U
		end
		if player.customtimer == 28 player.customtimer = 0
	else
		player.customtimer = 0
	end
end
end, MT_PLAYER)

It errors at line 37 for "attempting to perform arithmetic on field 'customtimer' (a nil value)" even though I set that to 0 earlier in the script. What could the issue be?
 
Code:
addHook("ThinkFrame", do
for player in players.iterate
	if player.reset == false
		player.customtimer = 0
		player.reset = true
	end
end
end)
This refers to the player structure.

Code:
addHook("MobjThinker", function(player)
	if player.state == S_PLAY_STND then
		player.customtimer = player.customtimer + 1
(etc..)
This refers to the player object, not the player structure, since you're using "MobjThinker", which is the object thinker's hook.

Code:
addHook("MobjThinker", function(mobj)
	local player = mobj.player
	if mobj.state == S_PLAY_STND then
		player.customtimer = player.customtimer + 1
(etc..)
This is about what you should be doing instead.
 
Okay, so I've made that change, but I still get the same error. I've also added somewhat of a fail-safe with a MapLoad hook but that still hasn't fixed it. Here's my updated code, if I may have done something wrong with the implementation.
Code:
addHook("MapLoad", do
for player in players.iterate
	player.reset = false
end
end)

addHook("ThinkFrame", do
for player in players.iterate
	if player.reset == false
		player.customtimer = 0
		player.reset = true
	end
end
end)

addHook("MobjThinker", function(mobj) do
	local player = mobj.player
	if mobj.state == S_PLAY_STND then
		player.customtimer = player.customtimer + 1
		if player.customtimer < 13 then
			mobj.frame = A
		end
		if player.customtimer > 12 and player.customtimer < 15 then
			mobj.frame = U
		end
		if player.customtimer > 14 and player.customtimer < 27 then
			mobj.frame = V
		end
		if player.customtimer > 26 and player.customtimer < 29 then
			mobj.frame = U
		end
		if player.customtimer == 28 player.customtimer = 0
	else
		player.customtimer = 0
	end
end
end
end, MT_PLAYER)
 
Code:
if player.customtimer == 28 player.customtimer = 0

You're missing an end statement here. You mentioned the error being on line 37, but the code you originally posted only has 29.
 
Last edited:
Code:
if player.customtimer == 28 player.customtimer = 0

You're missing an end statement here. You mentioned the error being on line 37, but the code you originally posted only has 29.

Oh, so I did. I forgot I had other testing stuff in there. My bad. Under the code I had posted most recently, it'd be on line 19. I added the end statement there to close that off, and removed one at the end, same error.
 
I hate to be "that" guy but uh...bump? I still have no idea why it's spouting this error.

I'm pretty sure MobjThinkers run before ThinkFrames, as, if I recall correctly, ThinkFrames only run after all other thinkers on the map have run.
 
Status
Not open for further replies.

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

Back
Top