Project won't recognise Platypus functions [SOLVED]

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.

However, when I try to create a platypus instance within my player script, it has parts of the code underlined.

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.

Thanks

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.

Put this at the top of your script:

local platypus = require "platypus.platypus"

You can see it in the Platypus example, e.g. here: platypus/example/grottoescape/player.script at master · britzl/platypus · GitHub

Thank you for the speedy reply.

I have added that at the top of my script and it now gives me a bunch of errors and my player movement is broken again.

Can you show the whole script?

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.)

Here is my platypus script:


when I hover over the blue dotted line it says unused variable ‘platypus’

And here is my player script:

I can consolidate them if need be. Thank you for taking a look.

Hold on I’m missing code form the Platypus file.

Here is the platypus file. I was missing the code to create an instance.

Config has the same error as before.

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.

Sorry. I haven’t used this forum before. I will do that for you know. Thank you for taking a look.

1 Like

Platypus script:

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

Error Message:

Build Errors:

Thank you for taking a look for me.

Thanks for formatting nicely.

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:

local config = {
		collisions = {
			separation = platypus.SEPARATION_RAYS,
			groups = {
				[hash("ground")] = platypus.DIR_ALL,
				--[hash("onewayplatform")] = platypus.DIR_ALL,
				[hash("onewayplatform")] = platypus.DIR_DOWN,
				[hash("onewaydoor")] = platypus.DIR_LEFT,
			},
			left = 4, right = 4, top = 7, bottom = 6, offset = vmath.vector3(0, 7, 0)
		},
		gravity = -800,
		max_velocity = 300,
		allow_double_jump = true,
		allow_wall_jump = true,
		allow_wall_slide = true,
		wall_slide_gravity = -50,
		debug = true,
	}

self.platypus = platypus.create(config)
2 Likes

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.

1 Like

Errors cascade into one another. When you get errors, best practice is to scroll up in the log to find the top one and address that first.

Thanks for the tip!

1 Like

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.

1 Like