Forum

> > CS2D > Scripts > How I can make a variable per tile?
Forums overviewCS2D overview Scripts overviewLog in to reply

English How I can make a variable per tile?

5 replies
To the start Previous 1 Next To the start

old How I can make a variable per tile?

Pseudon
User Off Offline

Quote
Hello, I need some help, I am trying to make a Lua script. I just started to work with entities and I am not doing so well.
1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("startround","_roundstart")
function _roundstart()
	for y = 0, map"ysize" do
		for x = 0, map"xsize" do
			if entity( x, y, "typename") == "Trigger_Use" then
				if entity( x, y, "name") == "shield" then
					[VARIABLE]=image( "gfx/flare3.bmp", x * 32 + 16, y * 32 +16, 0)
					imageblend([VARIABLE],1)
				end
			end
		end
	end
end
I need to be able to create a variable for each tile, I need them to set the images and to edit them later.
How can I set a variable for each tile?

old Re: How I can make a variable per tile?

VADemon
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if not pseudon then pseudon = {} end
pseudon.varpertile = {}

addhook("startround","_roundstart")
function _roundstart()
     for y = 0, map"ysize" do
          for x = 0, map"xsize" do
               if entity( x, y, "typename") == "Trigger_Use" then
                    if entity( x, y, "name") == "shield" then
                         pseudon.varpertile[x] = pseudon.varpertile[x] or {} -- indeed, thanks to Starkkz
                         pseudon.varpertile[x][y]=image( "gfx/flare3.bmp", x * 32 + 16, y * 32 +16, 0)
                         imageblend(pseudon.varpertile[x][y],1)
                    end
               end
          end
     end
end
UPD: Now it works
UPD1: Say thanks to user Starkkz
edited 2×, last 18.06.14 09:08:05 pm

old Re: How I can make a variable per tile?

mafia_man
User Off Offline

Quote
@user VADemon:
Nope it's not going to work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if not pseudon then pseudon = {} end
pseudon.varpertile = {}

addhook("startround","_roundstart")
function _roundstart()
     for x = 0, map"xsize" do
	  pseudon.varpertile[x] = {}
          for y = 0, map"ysize" do
               if entity( x, y, "typename") == "Trigger_Use" then
                    if entity( x, y, "name") == "shield" then
                         pseudon.varpertile[x][y]=image( "gfx/flare3.bmp", x * 32 + 16, y * 32 +16, 0)
                         imageblend(pseudon.varpertile[x][y],1)
                    end
               end
          end
     end
end

old Re: How I can make a variable per tile?

Infinite Rain
Reviewer Off Offline

Quote
Here:
1
2
3
4
5
6
7
tileVar = {}
for x = 0, map'xsize' do
	tileVar[x] = {}
	for y = 0, map'ysize' do
		tileVar[x][y] = 1 -- whatever variable
	end
end

Now, to access this variable, do:
1
tileVar[1][5] = 10 --tileVar[<x>][<y>]

Hope this helps.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview