Thinker Iteration Problem

Status
Not open for further replies.

Prisima

Member
Code:
hud.add(function(v, p)
	for mobj in thinkers.iterate("mobj")
		if not (mobj.type == MT_EMERALD1 | mobj.type == MT_EMERALD2 | mobj.type == MT_EMERALD3 | mobj.type == MT_EMERALD4 | mobj.type == MT_EMERALD5 | mobj.type == MT_EMERALD6 | mobj.type == MT_EMERALD7) return end
		print("TEST1")
	end
end, "game")

This code is supposed to print "TEST1" in the console whenever an Emerald mobj is found on the map, yet it does nothing. I am unsure what the problem is, but I think it's the iteration and that I'm not doing it right?
 
I think it's because... that's a HUD element you're trying to add to draw on the screen, not a MobjThinker hook. And HUD elements aren't supposed to have that many... "technical" things available, and the things it includes might not involve "print". *Tests* ...Well, "print" does work. Maybe you're just not allowed to run through thinkers like that in HUD elements? Not sure.
 
You're using symbols (|) for logical OR operations. Use the 'or' keyword.
 
I never knew the difference between ( | ) and ( or ) until now. Thanks, this thread can be locked because my script is working now.
 
Just a note for the future; if you get Lua scripts not working at all again, it helps to first test what happens if you addfile them to the game via the console. This way the console can alert you about any syntax errors in them, such as the issue in the script you posted (unless I'm mistaken).

Zwip-Zwap Zapony, I'm afraid you're just clutching at straws to find an explanation again. add.hook functions do allow you to reference mobjs and run thinkers.iterate and make print messages and so on; what they don't allow you to do is modify mobjs or players or any other part of the map, or call any function that does so for you.
 
Zwip-Zwap Zapony, I'm afraid you're just clutching at straws to find an explanation again. add.hook functions do allow you to reference mobjs and run thinkers.iterate and make print messages and so on; what they don't allow you to do is modify mobjs or players or any other part of the map, or call any function that does so for you.
I did test the print function, and came to the conclusion that does work in HUD elements, which I also wrote in the message. Then, because I like Prisima thought | was the same as or, went to question it might be because you can't run through iterators in HUD elements, since as you can't modify anything in them, the developers might have thought "these are useless for HUD stuff", and disabled them for HUD stuff.

I do admit, however, I should have gone much more in-depth on my testing before jumping to conclusions. Sorry. I'll try my best to remember to test everything before posting next time.
 
Status
Not open for further replies.

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

Back
Top