I need help on implementing a inventory system for my game

I want to be able to allow a inventory system where the player can be able to add and remove items i.e powerups or weapons but the limit is only 10 items in total. Im only asking for a framework for this.

I think this is a very broad question. I think it would benefit from narrowing down the scope of your question.
Are you talking about a visual representation of some items? If so, what are the visual goal? Do you have an example screenshot?

Agreed with comment above so many different ways to do this if you want it visual and they change how you would go about making the system. If doing text base much easier.

hi sorry i got carried away from doing larger objectives rather than focusing on the smaller ones, I will leave this for later as I have an issue where the game says:
image
For context: I am trying to send a message from the enemy.script where should the enemy die it spawns a item onto the players screen like a pickup item when a enemy is defeated.
The code from enemy.script is:

function drop_items(self)
	if self.enemy_health <= 0 then
		local enemy_pos = go.get_position()
		if self.drop_rate > 0.3 then
			msg.post("game:/scroll_spawner", "spawn scroll", {position = enemy_pos})
			print("scroll dropped", enemy_pos)
		else
			print("no scroll dropped")
		end
	end
end
the code for scroll_spawner is
function on_message(self, message_id, message, sender)
	if message_id == hash("spawn scroll") then
		factory.create("#scroll_factory", message.position)
		print("spawned scroll at: ", message.position)
	end	
end

i don’t know how to get rid of the error

Are you absolutely sure you have a game object with id scroll_spawner on the collection with id game? The error indicates that you don’t.

im trying to send a message to the scroll_spawner script that is within the scroll_controller object. The section of the code above is part of the enemy script where should enemy die it sends message to spawn a scroll but i cant figure out why its not sending the message.

Do print(msg.url()) in the script that you want to send a message to, and you’ll see the correct URL.

here is the hierarchy of objects

Have you done what I suggested? It will give you the right address to use.

like this?

No, in init(). Just so you can see what the URL actually is.

like this?

Almost. Missing an end to wrap up the init function.

it showed this as the debug output
DEBUG:SCRIPT: url: [game:/scroll_controller#scroll_spawner]

OK. That’s your answer. The correct URL is game:/scroll_controller#scroll_spawner but you used game:/scroll_spawner.

1 Like

thank you

No worries. Remember to use print(msg.url()) whenever you are unsure about addressing, it’s a great help.

1 Like