Coding help

SonicFan214

Member
I am attempting to make a code that enables the machine flag only when the character is doing the dash mode thing, so that why it will behave like Metal Sonic's dash mode. The code doesn't work. What am I doing wrong here?
Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "imnotrevealingcharname" 
			if player.dashmode > 3*TICRATE 
				player.machine = true
			else
				player.machine = false
			end
		end
	end
end)
 
I am attempting to make a code that enables the machine flag only when the character is doing the dash mode thing, so that why it will behave like Metal Sonic's dash mode. The code doesn't work. What am I doing wrong here?
Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "imnotrevealingcharname" 
			if player.dashmode > 3*TICRATE 
				player.machine = true
			else
				player.machine = false
			end
		end
	end
end)
The solution is that you need to set the SF_MACHINE flag in player.charflags, instead of setting player.machine.
 
You could have SF_MACHINE stored in the player.machine as that is less complicated than doing
Code:
player.charflags = $|SF_DASHMODE
Like this:
Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "imnotrevealingcharname" 
			if player.dashmode > 3*TICRATE 
				player.machine = true
			else
				player.machine = false
			end
                        if player.machine == nil
                           player.machine = SF_MACHINE
                        end
		end
	end
end)
 
Last edited:
You could have SF_MACHINE stored in the player.machine as that is less complicated than doing
Code:
player.charflags = $|SF_DASHMODE
[...]
Incorrect.
Adding the flag in player.charflags makes the character act like a machine for skin purposes.
Adding it anywhere else does nothing. Your extra line, for example, just stores a flag in a custom variable and nothing else.

Keep in mind that flags are merely constants holding a number. SF_MACHINE is a variable with a number, it doesn't literally mean SF_MACHINE in a way that placing it anywhere makes the player a machine.

I am attempting to make a code that enables the machine flag only when the character is doing the dash mode thing, so that why it will behave like Metal Sonic's dash mode. The code doesn't work. What am I doing wrong here?
Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "imnotrevealingcharname" 
			if player.dashmode > 3*TICRATE 
				player.machine = true
			else
				player.machine = false
			end
		end
	end
end)

player.machine doesn't control whether the player is a machine, since that's a custom variable. Check the wiki to know what variables does the player have.

You would need to do something like this:
Code:
addHook("ThinkFrame", function()
	for player in players.iterate do
		if player.mo and player.mo.skin == "imnotrevealingcharname" then
			if player.dashmode > 3*TICRATE then
				-- Add SF_MACHINE flag
				player.charflags = $ | SF_MACHINE
			else
				-- Remove SF_MACHINE flag
				player.charflags = $ & ~SF_MACHINE
			end
		end
	end
end)
Please, don't forget to add then and do after every condition. Also don't use do as a replacement for function().
 

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

Back
Top