scene actuator questions

ok it’s me again, this time my answer is simple and short.
can someone explain me how can i use scene actuator in a python script avoiding logic bricks?

thanks a lot

You know the scene actuator actually is a logic brick?

Look at the BGE API Docs. There you can see how you can configure it via Python.

this is the problem, i looked the api and i can’t understand how to do for example:

if i use bge.types.KX_SceneActuator.scene the api explain that “scene is the name of the scene to change exct” but how can pick a scene by the name if isn’t the current?

all this mess i’m causing it’s very important to me because i’m trying to make an in-game inventory but i want do it only via python script

There is no way to find out what scenes can be loaded. You have to know the potential scene names.

I do not understand what an inventory has to do with a scene. Usually a scene contains an inventory viewer (which represents the inventory model). You can implement the viewer with a mix of logic bricks and Python, while you keep the model as Python data structure.

There is no reason to avoid sufficient tools.

The logic bricks provide a nice GUI, so you do not need to write a lot of code for primitive settings such as scene names. In your case you get the loadable scenes in a dropdown list. I do not see how easier it can become.

ok , i made it, now the other question is how can i make the inventory to view objects in my inventory viewer?

There are several options.

Here is a quick proof of concept I made some days ago.

Usage:
click an object to “put it into inventory”
click a slot to “get the object back”

The inventory.adder just adds the object where it is. There is no logic that moves it around (such as moving under the mouse cursor). Feel free to add any logic you like.

notes:

Collectable objects should be placed at an hidden layer. Then add create a group with it in the level. This is because the object will be deleted and you can’t get it back when there is no copy.
(Attention: currently there is no filter, any detected object will be treated as collectable => modify inventoryController.collect() )

The inventory view consists of 8 slots, the prefix of each slot determines it’s slot id (0 - 8).
Each slot has a child that acts as clickable button.
Each slot has a child “Item.Empty” which presents the slot content (with the mesh that represents an empty slot). When the slot content changes, the mesh will be replaced. Make sure there is a mesh with the name: “Item.<collected object name>”.
Example: collectable object: Suzanne -> mesh name (in the inventory scene!): Item.Suzanne

The objects in both scenes communicate via messages. This means you can exchange the level scene, or remove/add the inventory (not included in the demo file).

Architecture:
MVC - Model, View, Controller (see Wiki)

The model contains a list of slots. Each slot contains one item. An item is the name of an object.

Have a look at the console. Inventory.printer prints the content of the inventory to console (sort of a second view).

As said, this was a proof of concept. You can use it, or just look how things are done and implement your own ideas.
I hope it helps you.

Attachments

inventory 2.1.blend (131 KB)

dude it’s amazing, thanks a lot, i try to understand how it work to do my own personal too, again thanks a lot i’ll post result when it’s finished

hi, it’s me again
i finished to write some pretty good scripts for my inventory system wich also include a method to save also the items (if they are in the inventory or the position where they are in the game etcetera…), now i’m thinking on how to do a good save/load system that save position of my player and for now npcs ( i think the method will works also on other objects, am i wrong?), any idea?
thanks again

Hi! you can take a look at this thread:

http://blenderclan.tuxfamily.org/html/modules/newbb/viewtopic.php?topic_id=41140&forum=3&post_id=500932#forumpost500932

It is a french forum but you can download the 4 files on the bottom of the page (“niveau” = level")

joueur = player
arrivée = end of level

Ah it seems there is a problem with ‘L’…

You have to edit line 49 of the SL.py (saveLoad) script (on the camera)… It’s a problem of relative/absolute path…

Ctrl to load last checkpoint
L to load last level reached
Alt+S to remove .bgeconf file (in level 1)(remove saved files)

thanks it works very well, i don’t like to copy so i’ll try to understand how it works and make my own method, again really helpful, thank you

i’m trying to implement the inventory that i done with my model’s animations but i had some problems wich i can’t understand how to resolve:
in my scene i have an empty related with my character’s bone “handBone”, when i select an object from the inventory it spawns at the empty position and all seems great but i noticed that the item, whatever it is, it’ s bigger than the item on the ground, i tried set the empty “clear _Parent” and in this case, when the item spawns, the dimensions are proper
help me please, because i need the item to move as my carachter

Spawning objects will inherit the transformations of the spawning object - that is the position, orientation and scaling. Set the scaling on the spawn object to 1 to avoid this.

ok as soon as i’ve finished to eat i try

ok so this is the piece of code that spawns the weapons when equiped
the dict “armi_attive” is written in italian so armi_attive = active_weapons

there are no indentations but in the code of course they are present

i add this line:
spawn.objectLastCreated.localScale[1,1,1]

but debugger says that vector indices must be integers, not tuple.
why have i this kind of error?

spawn = controller.actuators[“spawn”]

if len(own.children) == 0: spawn.object = global_Dict[“armi_attive”]
spawn.instantAddObject()
spawn.objectLastCreated.setParent (own)

elif str(own.children[0]) != global_Dict[“armi_attive”]:
own.children[0].endObject()
spawn.object = global_Dict[“armi_attive”]
spawn.instantAddObject()
spawn.objectLastCreated.setParent (own)