Code: Select all
Graphics.sprites.npc[278].img = Propeller block Mario
end
if player.character==Character_Luigi then
Graphics.sprites.npc[278].img = Propeller block Luigi
end
if player.character==Character_Peach then
Graphics.sprites.npc[278].img = Propeller block Peach
end
if player.character==Character_Toad then
Graphics.sprites.npc[278].img = Propeller block Toad
end
There's a glaring problem with this code that somehow went unnoticed. You're trying to use variable names with spaces in them. You can't do that. Lua will recognize "Propeller block Mario" as 3 separate variables and get confused as to what you want it to do with them. This is what's causing your error. You should replace the spaces with underscores or just remove them and use camelCase in the names (i.e. "propeller block Mario" becomes "propellerBlockMario")
Also, just an FYI, capitalizing the first letter of your variable names is usually considered bad naming convention. They should generally start with lowercase letters.
yoshiegg wrote:Thank you.I think I mostly got it now but how do I specify which npc should be affected by the lua code? Furthermore, I also wonder if this would also work for the new 2.0 chars and other graphics like e.g. blocks or tiles on the world map?
You would use this in onDraw (since this needs custom images to be drawn):
Code: Select all
for k,v in pairs (NPC.get(278, -1)) do
-- You would put the code you want to apply to the propeller block here
end
World map stuff is a bit less developed in LunaLua, so I'm not sure if this would work on world map graphics so well. I don't really know how the new characters work, but I don't think they use the same ID system as vanilla SMBX characters.
yoshiegg wrote:So now I think I can proceed with writing the code. However, I don't know how to do the frame setup in the code.Over that, I want to know if the npc offset uses numbers (eg. 1 for Mario) or letters (CHARACTER_MARIO) to define the player holding the object.
You should override the Propeller block's image with a blank one, then add a column to your image for each player who uses it. (You may want to add another row onto the front of your image for when no one is holding it)
Then, you need to use DrawImageToSceneWP to draw your image. Use the version with the sourceX, sourceY, width, and height arguments to draw only the part of the image that should be shown.
CHARACTER_MARIO is a constant that equals 1, so either way would be the same.
You seem to be fairly new to Lua, so you might want to look at some tutorials for anything you don't understand.