Make new variables when defining a mobj

Elle-P

Member
When creating a mobj, there are variables that you can set to be used such as speed, mass, etc. Is there a way to add custom variables that can be used? If you need to create a new list, is there a way to make it so collision still works? I'm also confused about when you add .mo to the middle when using variables.
 
I'm assuming by "creating a mobj" you're talking about Lua and the part where you write a big table for mobjinfo.

Is there a way to add custom variables that can be used?
Technically you can add custom variables to mobjinfo, but they are not going to be automatically written to the spawning mobj when it spawns. However, you can reference them through <mobj_t>.info.<your_var>.

An example:
freeslot("MT_DUMMY")
mobjinfo[MT_DUMMY] = { -- create an extremely basic object
    spawnhealth = 1,
    spawnstate = S_INVISIBLE
}
mobjinfo[MT_DUMMY].hello = "hi!" -- custom mobjinfo field

addHook("MobjThinker", function(mobj)
    print( mobj.info.hello ) -- print that here
end, MT_DUMMY)
(Note how I'm declaring custom variables outside the main table. This is because SRB2 drops any custom table field when defining the object with a table.)

Note that you can just use a MobjSpawn hook instead and set a custom variable as soon as a mobj of a specific type spawns.

If you need to create a new list, is there a way to make it so collision still works?
This question does not make sense. Can you rephrase this question?

I'm also confused about when you add .mo to the middle when using variables.
This is only relevant when working with players.

Players are split in two parts: You've got the abstract player_t that holds stuff like inputs, lives, whether it's a spectator or not and the like, and its relevant mobj_t which is the thing that jumps, moves, displays a sprite and generally exists in the map and interacts with other objects.

When you're looking to modify a player's object, you can access it through <player_t>.mo. It only exists if the player is not spectating.
No other userdata types have a mo field.
 
Thank you! That is what I was referring to. Thanks for the clarification on .mo too. Defining the variables in a MobjSpawn hook for the object type works perfectly!
 

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

Back
Top