Cuberite Forum
2 arguments in same local or same value - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: 2 arguments in same local or same value (/thread-1251.html)

Pages: 1 2


2 arguments in same local or same value - tonibm19 - 09-30-2013

I'm trying to store 2 return values in the same local and then store it in a ini file.
Here is the code I made:
Code:
function HandleChunkCommand( Player, Entity )
      ChunksIni = cIniFile( "chunks.ini")
      local ChunkPos = Entity:GetChunkX(),Entity:GetChunkZ()
      ChunksIni:SetValue(ChunkPos,   "Claimed",   1)
      ChunksIni:WriteFile()
      return true
end
It only stores ChunkX, no ChunkZ.
If I do print(Entity:GetChunkX(),Entity:GetChunkZ()) it gives me chunkX and ChunkZ but how can I store it in a local?


RE: 2 arguments in same local or same value - bearbin - 09-30-2013

Easiest thing to do would be to insert both into a table and then join.


RE: 2 arguments in same local or same value - FakeTruth - 09-30-2013

You cannot store two values in a single variable...
Try this:
Code:
ChunksIni:SetValue(Entity:GetChunkX() .. ":" .. Entity:GetChunkZ(),   "Claimed",   1)



RE: 2 arguments in same local or same value - NiLSPACE - 09-30-2013

This should work:
local ChunkPosX, ChunkPosZ = Entity:GetChunkX(), Entity:GetChunkZ()
you can't store two values in one variable.


RE: 2 arguments in same local or same value - tonibm19 - 09-30-2013

Undecided Having more problems
Code:
function HandleClaimChunkCommand( Player, Entity )
      ChunksIni = cIniFile( "chunks.ini")
      ChunksIni:ReadFile()
      if (ChunksIni:FindKey(Entity:GetChunkX() .. ":" .. Entity:GetChunkZ())<0) then
            ChunksIni:AddKeyName(Entity:GetChunkX() .. ":" .. Entity:GetChunkZ())
            ChunksIni:SetValue(Entity:GetChunkX() .. ":" .. Entity:GetChunkZ(),   "Claimed",   1)
            ChunksIni:WriteFile()
      else
            Player:SendMessage("This chunk is already claimed")
            return true
      end
      return true
end
Why does it tell SendMessage is a nil value?

I tested with a simple command that sends you a message and you need to use split in the function, but in my command if I use Split then Entity is a nil value and I cant get chunk pos


RE: 2 arguments in same local or same value - tonibm19 - 09-30-2013

Fixed myself Smile


RE: 2 arguments in same local or same value - xoft - 09-30-2013

You've mixed up the parameters, they are (Split, Player), not (Player, Entity)

Still, basing any kind of protection scheme on cIniFile is a really really bad idea.


RE: 2 arguments in same local or same value - tonibm19 - 09-30-2013

(09-30-2013, 11:20 PM)xoft Wrote: Still, basing any kind of protection scheme on cIniFile is a really really bad idea.
Why?


RE: 2 arguments in same local or same value - NiLSPACE - 10-01-2013

Its slow


RE: 2 arguments in same local or same value - tonibm19 - 10-02-2013

My plugin it's going fine, commands are nearly done, but then I'll need to do hooks. Hope it's finished soon. It will be the first plugin to let players claim areas without the need of an admin.