Lua Help: Growth Monitor

Status
Not open for further replies.

Dimpsuu

Dimpsy
So ya know the Growing Monitor from Knuckles Chaotix which increases one's height for a short period of time? Yea I was trying to make that in SRB2 and I'm having a bit of a problem here trying to make the lua script itself work as it should.

function A_KCGrow(actor, var1, var2)
local receiver = actor.target
if not receiver.player.kcgrow_power then
receiver.player.powers[pw_speedshoes] = 0
end
S_StartSound(receiver, actor.info.seesound)
end

addHook("ThinkFrame", do
for player in players.iterate
and (kcgrow_power == 1)
and not player.kcgrow_used
if player.mo.flags2 & MF2_OBJECTFLIP
player.mo.flags2 = $1 & ~MF2_OBJECTFLIP
S_StartSound(player.mo, sfx_shield)
else
player.mo.flags2 = $1 | MF2_OBJECTFLIP
S_StartSound(player.mo, sfx_shield)
end
player.kcgrow_used = true
end
if P_IsObjectOnGround(player.mo) then
player.kcgrow_used = false
end
end)

addHook("MobjSpawn", function(mo)
mo.scaleinit = 1
mo.normscale = mo.scale
mo.growscale = mo.scale*2
mo.banim = 0
mo.oldbuttons = 0 // stores what buttons were pressed last tic
end, MT_PLAYER)

// Function for MobjThinker hook to use, required to be in function(mobj) format
// "return false" or "return" on its own allows the normal behaviour to carry on as normal after this
// "return true" would make this stop the normal behaviour from running after this
// in this case at least we don't need to (or want to) overwrite normal player behavior, that would cause some problems!
local function HandleBrakScale(grow)
if player.kcgrow_power then
mo.player.kcgrow_power = false
return
end

if grow.normscale == nil or grow.growscale == nil
grow.normscale = grow.scale
grow.growscale = grow.scale*2
end

if (player.kcgrow_power == 1)
if grow.scaleinit
grow.scale = grow.growscale // set to cbfs scale
grow.scaleinit = 0
end
else //normal skins - switching skins is properly supported now!
if grow.scale == grow.growscale
grow.scale = grow.normscale
end
grow.scaleinit = 1
end
end

addHook("MobjThinker", HandleBrakScale, MT_PLAYER)

Am I doing something wrong?
 
...How many times have I got to say that you can't arbitrarily use things such as "player" and "mo" without them meaning something first?

See your HandleBrakScale(grow) function: "grow" is intended to be a variable representing the userdata for an object. It is the only variable you're supplied with by the function!

So, for instance "mo.player.kcgrow_power" means nothing because what is "mo" in this context? If you actually think about it, "mo" means absolutely nothing here! Presumably "mo" is an object, so really it should be "grow.player" for your purposes.

Equally so, "player.kcgrow_power" means nothing because you have started off with just "player" and that means absolutely nothing in the context of the function too. Either you start off the function with "local player = grow.player" or you use "grow.player" instead, as "grow" is a valid variable here and "grow.player" is then a variable that is part of the object structure for "grow".

tl;dr: In HandleBrakScale, replace "mo.player.kcgrow_power" with "grow.player.kcgrow_power" and "player.kcgrow_power" with "grow.player.kcgrow_power".


If you're familar with such concepts, please excuse me; other than HandleBrakScale everything seems fine at a glance.
 
Status
Not open for further replies.

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

Back
Top