You need to have the scene running in order for it to receive the messages.
You should separate the view from the model to do this. In other words, the scene you add and remove should not manage the inventory, it should only display it. A simple way to manage this is to have an object (like an empty) manage the inventory in the main scene. It can receive the same messages you currently send, and store the inventory in bge.logic.globalDict (a globally accessible dictionary). The scene used for displaying the inventory can read the state of the inventory from this dictionary.
What to do if I want to transfer a property from one scene to other and than show that property in text? is it possible to do it with Message if the property is being sent as integer?
Now I got a problem- how do I make the inventory work like this:
if cell 1 is empty or contains ammo: add ammo to cell 1
if cell 1 is filled with something that’s not armor and it is not empty and the cell 2 is free or contains ammo: add ammo to cell 2.
I tried something, but I am stuck here:
import bge
from bge import logic
scene = logic.getCurrentScene()
objects = scene.objects
def cell1():
cont = logic.getCurrentController()
own = cont.owner
sens = cont.sensors
act = cont.actuators
act_9mm= cont.actuators['9mmCol']
ammo9 = sens["col9mm"]
if own["count"] < 1:
own["item"] = 0
if ammo9.positive:
if own["item"] == 0 or own["item"] == 1:
own["count"] += 15
own["item"] = 1
cont.activate(act_9mm)
def cell2():
cont = logic.getCurrentController()
own = cont.owner
sens = cont.sensors
act = cont.actuators
act_9mm= cont.actuators['9mmCol']
ammo9 = sens["col9mm"]
if own["count"] < 1:
own["item"] = 0
if ammo9.positive:
if
if own["item"] == 0 or own["item"] == 1:
own["count"] += 15
own["item"] = 1
cont.activate(act_9mm)['9mmCol']
ammo9 = sens["col9mm"]
if own["count"] < 1:
own["item"] = 0
if ammo9.positive:
if own["item"] == 0 or own["item"] == 1:
own["count"] += 15
own["item"] = 1
cont.activate(act_9mm)
I need to call the first cell empty in the empty if inside of the cell2(). Also I want to find out if this syntax is correct. How can I check for the first cell’s emptie’s property item inside of cell2()?
As you see, the cell2() is using the same method, but doesn’t seem to work now… When I set it to use item 2 in InvCell1 object, I can’t collect the ammo in the second cell. Anyway, when the cell 1 is empty or has some ammo(ID 1) in it, I can collect more.
I see so the and works strange- it desn’t work as excepted- altought it gets True and True, it sends False, but when I get True or False I get True? Khm… Why doesn’t it work with and?
OK! For the handgun I can use if firstC[“item”] > 1: , but I can’t use it for other- what to do- what to use for and that checks if the item is nor the ID of collected item, nor 0 and if both conditions are true(item isn’t the collected item ID or 0), than it continues condition.
import bge
from bge import logic
scene = logic.getCurrentScene()
objects = scene.objects
def cell1():
cont = logic.getCurrentController()
own = cont.owner
sens = cont.sensors
act = cont.actuators
act_9mm= cont.actuators['9mmCol']
ammo9 = sens["col9mm"]
if own["count"] < 1:
own["item"] = 0
if ammo9.positive:
if own["item"] == 0 or own["item"] == 1:
own["count"] += 15
own["item"] = 1
cont.activate(act_9mm)
def cell2():
cont = logic.getCurrentController()
own = cont.owner
sens = cont.sensors
act = cont.actuators
act_9mm= cont.actuators['9mmCol']
firstC = scene.objects["InvCell1"]
ammo9 = sens["col9mm"]
if own["count"] < 1:
own["item"] = 0
if ammo9.positive:
if firstC["item"] != 1 and firstC["item"] != 0:
if own["item"] == 0 or own["item"] == 1:
own["count"] += 15
own["item"] = 1
cont.activate(act_9mm)
Hi! I can see you’re working hard to get your script to work, but you might want to step back and take a think about how it’s working and what you want it to do.
It might be much easier to make a dictionary based inventory.
I’ll be posting a short tutorial about that in the resources forum shortly.
It won’t be easier for me as I don’t understand that method myself. As I need resident evil first series type tactics, I need inventory like this. Anyway, it owrks now…