Forgottenserver: [Question] Game.createTile(pos)

Created on 24 Jan 2017  路  10Comments  路  Source: otland/forgottenserver

When I use this function Game.createTile(pos) where there is no ground, I will be able to create a ground on this position with Game.createItem(424, 1, pos) after, right? Now, if I remove this ground id 424 with ground:remove(), I will still be able to add a ground on this pos again with Game.createItem, if I want.

I think something memorize the new tile on this pos when I make able to create items on this pos with Game.createTile.
So , the questions are:

  1. If I want to make unable to create items on this pos after remove the items including the ground (with something like Game.removeTile(pos), but I could not find a function like that), what should I do?
  2. Or can I let this way?
  3. It will not consume too much memory if do Game.createTile(pos) (without create items and ground) with lots of positions?

Example:

  1. Game.createTile(pos) -- Now we are able to create items on that position
  2. Game.createItem(424, 1, pos) -- Created a ground on this position
  3. local tile = Tile(p) local ground = tile:getGround() ground:remove() -- Removed the created ground
  4. Game.createItem(724, 1, pos) -- Created another ground on this position (we are still able to do this)
  5. local tile = Tile(p) local ground = tile:getGround() ground:remove() -- Removed the created ground
  6. I want to disable the tile on this position, because there is nothing there and I think it will consume too much memory when have lots of tiles able to create items even if there is nothing.

Thanks in advance! :)

question

All 10 comments

lua should automatically collect garbage for the tiles

i did my own little test and used a loop to create 10,000 tiles

before tiles 1105.3349609375
after tiles 2241.8583984375

before garbage collection 2243.0009765625
after garbage collection 1103.9853515625

the numbers are KB of memory used, 10k tiles only took a little over 1mb of memory, so you shouldn't worry about it
you can let lua take care of the garbage collection itself, or you can run it in your script with collectgarbage("collect") if you really feel the need to

@Vulcanx your comment has absolutely no relation to the question.

@Riverlance you can not remove a tile with ground:remove() or by any other functions.

Let me try to explain again step by step using codes.

  1. Tried to create a tile. Nothing happens, because there is no virtual tile created.
    local toPos=player:getPosition()
    toPos.y=toPos.y+1
    Game.createItem(424, 1, toPos) -- Tried to create a tile WITHOUT creating a virtual tile before
    image

.

  1. Tried to create a tile. The ground item was created successfully, because there is a virtual tile created before.
    local toPos=player:getPosition()
    toPos.y=toPos.y+1
    Game.createTile(toPos) -- Created the virtual tile
    Game.createItem(424, 1, toPos) -- Created the ground id after the virtual tile creation
    image

.

  1. I removed the ground item id 424, but the virtual TILE is still there. If is possible to remove the ground id, why I cannot remove it, @ranisalt ?
    local toPos=player:getPosition()
    toPos.y=toPos.y+1
    local tile=Tile(toPos)
    local ground=tile:getGround()
    ground:remove() -- Removed the ground id, but the virtual tile is still there
    image

.

  1. Now, I will do the step 1 again, that is to create a ground id without create the virtual tile. It worked, because there is still the virtual created on step 2.
    local toPos=player:getPosition()
    toPos.y=toPos.y+1
    Game.createItem(424, 1, toPos) -- I still can create the ground id because the virtual tile is still there
    image

.

So, on the step 4, we see that is still possible to create a ground on that position because something _memorize the virtual tile on that position_. What I need to know is how can I remove this virtual tile for block me the possibility of create a ground id on there and for clean the virtual tile from the memory also. Why I would need this? E.g., I could create a fly system with this that create voids around and remove the old ids after walk.

Thank you guys.

@ranisalt he asked about memory because he thought it would take up lots of memory
but ok sure it was in no way related

@Vulcanx didn't catch my eye on there.

@Riverlance Game::internalRemoveItem, first condition is it's not possible to remove an item if it has no parent, and grounds have no parent.

But I removed and it worked. o-o
I need a way to remove the full ground and a way to create the ground back.
There is any way to do this?

Why would you need to remove it, unless you have really low memory to run your server this won't even make significant difference, anyway the tiles are going to be reusable so you don't have to create them all the time, only once. That's better than creating and deleting a tile every time.

@Mkalo The fly system creates and deletes the void tiles on the player movement. So, if there is many players flying, there will be a lot of created tiles. It really does not makes any difference? So I just need to create and remove the void ground and let the created virtual tile there? Thanks.

@Vulcanx

@Riverlance
The lua objects that represent a game tile will be garbage collected when not used, however, it is currently impossible to safely remove a tile (So once a tile is created the C++ side representation of a tile and its corresponding floor portion will remain allocated until server restart).

@Riverlance
I'm closing this issue. If you still have questions regarding this functionality, feel free to reopen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MillhioreBT picture MillhioreBT  路  4Comments

irenicus30 picture irenicus30  路  5Comments

dudantas picture dudantas  路  4Comments

marksamman picture marksamman  路  3Comments

EPuncker picture EPuncker  路  3Comments