Hello again and sorry for the very low programmer question…
I making a game where a GO make a level, in a table, that table will be used in many other scripts(i belive)
I basic using that table data to place the tiles and futher script will collect that data to make the collision map and the monster map … so how do my player GO can get that info … like :
Before step to anywhere, check if the table collision is not blocking and if there is a monster on the monster map attack it instead to walk…
if collisionmap[x][y] == 1 then -- do nothing else move() -- only an idea end
So you want to create a tile/grid based game where you can move your hero around and easily detect collisions with walls and monsters? To detect collisions with walls and monsters you should look into using the physics system to detect collisions. Look at the documentation for collision shapes and physics.
I want access the info on the table from another gameobject, collision by physics i far more expansive and, dont solve the problem … because since it will be an RPG i will all the time need to access data in table inside other GO … exemple: i need acquire the armor class of some enemy to then roll the attack on the player and the same is true for the monster … and a pathfinder will also need a information like that. The applicability of the question is far more important the collision subject… i only used the example because i’m implement my love2d game on defold step by step … trying to ajust, because now im working with prefabs, its differente from what i was using on love2d.
I see. Ok, if you want a data structure to hold the map and have it accessible from many different places then you could perhaps store it in a Lua module and require that module from all scripts that need access to the structure of the map, for anything from Line of Sight calculations to path finding and so on.
its not possible use go.get("/main/level#createlevel", level[x][y]) ? or something like that?
Because even with modules there is some things that will belong to a GO specific like: players Armor class or monsters Armor class … it will not be possible access that value from modules right?
If it is so hard access variables on another GO, that prefab system need be changed in a hurry.
I was having a feeling i will need to make a single game Object to manege everything … he only move GO around like the player or the monsters, control animations … but that kind of structure looks very bad in a prefab enviroment.
Plz make some ajusts to easy access variables from GO. that is a must i think.
Any other solutions will be very well accepted guys
Then you can read that property from any script like this:
local armor = go.get("url_to_game_object", "armor")
This is slower than accessing a value from a Lua module though so it should be used sparingly. The question is why one game object needs to know the armor class of another game object? Wouldn’t it be better for the first game object to post an attack message with the strength of the attack to the target game object and let that game object deduct armor class when calculating the amount of damage actually inflicted?
Thats an good idea, but that dont makes the normal way to access variables, less important, as you can see in the case of an attack you could send a msg to solve, mas how to check for the level for a pathfinder?
And this is only slower, because we need to go through GO.property, if a normal way to access variable was accessible, that would be faster right?
One question rises, i can store a table as a property of a GO?
In our previous game (a gridbased game) we chose to work with the full grid as a module which worked very well. Sometimes you just need a fast access to bigger storage of data and this helped us to use that grid-module for matchmaking etc.
Also in a couple of games I’ve been doing some A* pathfinding and also then used this way of design.
Another way of tackling this is like we are doing now in our current project. We have created a help-module that stores global tables that you want to share between components within a gameobject (eg several scripts in the same gameobject) OR between gameobjects.