I am an inexperienced programmer so I apologise if this is a simple mistake but my project doesn’t appear to be implementing Platypus correctly. I have added it as a library dependency and it shows up at the side as a .lua file.
It says the same thing when I hover over config. It may be because I haven’t configured properly however, as I am not very practised in programming or using Defold and I haven’t used Platypus before , I am unsure how to solve the problem. I followed both a guide on how to add library depndencies and have read through the READ.me for Platypus and just can’t figure it out.
I am using Platypus so I can implement jumps into my platformer. I initially added it to my player script (with the same problem) but I have now added it to a separate script file and attatched it to the player game object. This is because the same line of code was breaking the movement I already had. If it needs to be moved back then I can obviously do that however, the problem still remains.
If anyone can help, it would be greatly appreciated as this is for a school project. I’m open to any suggestions.
Had a quick look and it’s not really clear in the documentation, but in order to access a Lua module (.lua file) you need to require it in your script first.
Ignore the part about my player movement being broken I’ve fixed that (I accidentally had self.platypus = platypus.create(config) still amongst the player script.)
First of all, in the future I suggest you share actual code rather than images. If you wrap it like this:
```
Code here
```
It comes out nicely formatted like this:
Code here
Secondly I think we are a bit muddled here. The error you shared does not match the script you have shared. You need to run your project again and make sure you share the error as it is right now.
local platypus = require "platypus.platypus"
function init(self)
self.platypus = platypus.create(config)
end
function update(self, dt)
self.platypus.update(dt)
end
function on_message(self, message_id, message, sender)
self.platypus.on_message(message_id, message)
end
function on_input(self, action_id, action)
if action_id == hash("jump") then
if action.pressed then
self.platypus.jump(800)
elseif action.released then
self.platypus.abort_jump(0.5)
end
end
end
Player Script:
local normalSpeed = 200
function init(self)
msg.post(".", "acquire_input_focus")
self.vel = vmath.vector3()
end
function update(self, dt)
local pos = go.get_position()
pos = pos + self.vel * dt
go.set_position(pos)
end
function on_input(self, action_id, action)
if action_id == hash("forward") then
if action.pressed then
self.walk = true
self.vel.x = normalSpeed
sprite.play_flipbook("#Player_sprite", hash("Walk_forward"))
elseif action.released then
sprite.play_flipbook("#Player_sprite", hash("Idle_forward"))
self.vel.x = 0
self.walk = false
end
end
if action_id == hash("backward") then
if action.pressed then
sprite.play_flipbook("#Player_sprite", hash("Walk_backward"))
self.vel.x = normalSpeed * -1
self.walk = true
elseif action.released then
sprite.play_flipbook("#Player_sprite", hash("Idle_backward"))
self.vel.x = 0
self.walk = false
end
end
end
Your warning about config being undefined means that you are using a variable (config) that hasn’t been defined. It’s equivalent therefore to passing nil to platypus.create(). I expect that the error you have shared isn’t the first thing that comes up. I expect you see this before?
You must provide a config
Here is documentation about configuring a platypus instance:
Here’s an example of it being done in practice:
In the example above, config isn’t declared as a separate variable. For clarity, this is equivalent:
Thank you for all your help. I thought it was probably a configuration issue but with my lack of experience I was unsure how to solve it. There is an error that says ‘You must provide a config’ but I missed it as the other error message was repeatedly duplicated so it was buried. I really appreciate you taking out the time to help me. I shall take a look at the examples now.
I am currently trying to configure my player. This is the code that I have.
local platypus = require "platypus.platypus"
local config = {
collisions = {
separation = platypus.SEPARATION_RAYS,
groups = {
[hash("ground")] = platypus.DIR_ALL,
[hash("logs")] = platypus.DIR_ALL
},
left = 22, right = 22, top = 35, bottom = 43, offset = vmath.vector3(0, 0, 0)
},
gravity = -800,
max_velocity = 300,
allow_double_jump = false,
allow_wall_jump = false,
allow_wall_slide = false,
wall_slide_gravity = nil,
debug = true,
}
function init(self)
self.platypus = platypus.create(config)
end
function update(self, dt)
self.platypus.update(dt)
end
function on_message(self, message_id, message, sender)
self.platypus.on_message(message_id, message)
end
function on_input(self, action_id, action)
if action_id == hash("jump") then
if action.pressed then
self.platypus.jump(800)
elseif action.released then
self.platypus.abort_jump(0.5)
end
end
end
I’ve set the size of the hit box to fit the player. However, I don’t understand how to configure the collision groups. I’ve looked at the examples and the documentation and it just isn’t clear enough for me to understand. I assume that platypus.DIR_ALL has something to do with the directions in which the player can collide with said objects but I am unsure how I am supposed to link them to the actual game objects such as the ground. I assume it will involve me creating a platypus instance within my ground game object but I am still unsure how to go forward.
If you are able to help, I would appreciate it but if not, no worries.
I don’t actually use platypus myself so we are reaching the edges of my knowledge.
It looks like you need to create and place collision objects, likely static ones for things like ground. The collision object manual is here: Collision objects in Defold
There is an example in the platypus repo - you should be able to download that project and poke around in it to see how the example there is set up.