Page 22 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Thu May 12, 2016 2:58 pm
by Nerx
How can I spawn in a block on a specific layer?

Re: Need help with lua? - LunaLua General Help

Posted: Thu May 12, 2016 4:13 pm
by S1eth
Nerx wrote:How can I spawn in a block on a specific layer?
Don't you just do this?

Code: Select all

local myBlock = Block.spawn(number blockId, number x, number y)
myBlock.layerName = "myLayerName" --this?  
myBlock.layerObj = Layer.get("myLayerName") --or this  (or both?) 
Given, I've never needed to spawn any blocks. That code is just what looking at the API page for 10 seconds got me.

Re: Need help with lua? - LunaLua General Help

Posted: Thu May 12, 2016 4:32 pm
by Nerx
S1eth wrote:
Nerx wrote:How can I spawn in a block on a specific layer?
Don't you just do this?

Code: Select all

local myBlock = Block.spawn(number blockId, number x, number y)
myBlock.layerName = "myLayerName" --this?  
myBlock.layerObj = Layer.get("myLayerName") --or this  (or both?) 
Given, I've never needed to spawn any blocks. That code is just what looking at the API page for 10 seconds got me.
Aren't layerObj and layerName read-only though? That's what the wiki says at least

Re: Need help with lua? - LunaLua General Help

Posted: Fri May 13, 2016 8:00 pm
by PixelPest
Nerx wrote:
S1eth wrote:
Nerx wrote:How can I spawn in a block on a specific layer?
Don't you just do this?

Code: Select all

local myBlock = Block.spawn(number blockId, number x, number y)
myBlock.layerName = "myLayerName" --this?  
myBlock.layerObj = Layer.get("myLayerName") --or this  (or both?) 
Given, I've never needed to spawn any blocks. That code is just what looking at the API page for 10 seconds got me.
Aren't layerObj and layerName read-only though? That's what the wiki says at least
You can define the layer as:

Code: Select all

local myLayerName = Layer(#)
Replace number with the number the layer is in the list. (Default layer is 0.)
myLayerName also shouldn't be in quotes since it's a variable

Re: Need help with lua? - LunaLua General Help

Posted: Fri May 13, 2016 8:04 pm
by Emral
PixelPest wrote:
S1eth wrote:
Don't you just do this?

Code: Select all

local myBlock = Block.spawn(number blockId, number x, number y)
myBlock.layerName = "myLayerName" --this?  
myBlock.layerObj = Layer.get("myLayerName") --or this  (or both?) 
Given, I've never needed to spawn any blocks. That code is just what looking at the API page for 10 seconds got me.
You can define the layer as:

Code: Select all

local myLayerName = Layer(#)
Replace number with the number the layer is in the list. (Default layer is 0.)
myLayerName also shouldn't be in quotes since it's a variable
No. What S1eth wrote is correct. And I think you can write to layerName and layerObj.
layerName requires a VB6Str (String layername)
layerObj requires the layer object. Essentially what you wanted to assign to layerName in your post.

Re: Need help with lua? - LunaLua General Help

Posted: Fri May 13, 2016 8:08 pm
by mariogeek2
Hey guys, I'm a little curious, is there anyway to make an NPC behave as if it's in water, even if it's not? I mean the entire specific NPC population, not just a single one (I can do that with attach water layer). For example, a generator of slow rexes.

Don't be in any rush to respond. It's not something I'm working on right now. I've just got an idea for a level in the future.

Re: Need help with lua? - LunaLua General Help

Posted: Fri May 13, 2016 8:10 pm
by PixelPest
mariogeek2 wrote:Hey guys, I'm a little curious, is there anyway to make an NPC behave as if it's in water, even if it's not? I mean the entire specific NPC population, not just a single one (I can do that with attach water layer). For example, a generator of slow rexes.

Don't be in any rush to respond. It's not something I'm working on right now. I've just got an idea for a level in the future.
NPC.underwater. You can use NPC.get() to grab all NPCs

Re: Need help with lua? - LunaLua General Help

Posted: Fri May 13, 2016 8:11 pm
by mariogeek2
PixelPest wrote:
mariogeek2 wrote:Hey guys, I'm a little curious, is there anyway to make an NPC behave as if it's in water, even if it's not? I mean the entire specific NPC population, not just a single one (I can do that with attach water layer). For example, a generator of slow rexes.

Don't be in any rush to respond. It's not something I'm working on right now. I've just got an idea for a level in the future.
NPC.underwater
OK, great, thx. That's all I needed to know.

Re: Need help with lua? - LunaLua General Help

Posted: Fri May 13, 2016 11:11 pm
by MECHDRAGON777
Image
I was wondering why the block swap was not working... (Yes, the graphics are loaded.

Code: Select all

------------------------------------------------------------------------------
-----------------MECHDRAGON's SCREEN 8----------------------------------------
------------------------------------------------------------------------------
--load images
local ☢霊烏路空☢ = {}
☢霊烏路空☢.nba24 = Graphics.loadImage("Nuclear Tileset\nuclaerba-24.png")
☢霊烏路空☢.nba57 = Graphics.loadImage("Nuclear Tileset\nuclaerba-57.png")
☢霊烏路空☢.nba62 = Graphics.loadImage("Nuclear Tileset\nuclaerba-62.png")
☢霊烏路空☢.nba66 = Graphics.loadImage("Nuclear Tileset\background-66.png")
☢霊烏路空☢.nba67 = Graphics.loadImage("Nuclear Tileset\nuclaerba-67.png")
☢霊烏路空☢.nba69 = Graphics.loadImage("Nuclear Tileset\nuclaerba-69.png")
☢霊烏路空☢.nba75 = Graphics.loadImage("Nuclear Tileset\nuclaerba-75.png")
☢霊烏路空☢.nba76 = Graphics.loadImage("Nuclear Tileset\nuclaerba-76.png")
☢霊烏路空☢.nba78 = Graphics.loadImage("Nuclear Tileset\nuclaerba-78.png")
☢霊烏路空☢.nba79 = Graphics.loadImage("Nuclear Tileset\nuclaerba-79.png")
☢霊烏路空☢.nba87 = Graphics.loadImage("Nuclear Tileset\background-87.png")
☢霊烏路空☢.nba95 = Graphics.loadImage("Nuclear Tileset\nuclaerba-95.png")
☢霊烏路空☢.nba97 = Graphics.loadImage("Nuclear Tileset\nuclaerba-97.png")
☢霊烏路空☢.nba99 = Graphics.loadImage("Nuclear Tileset\nuclaerba-99.png")
☢霊烏路空☢.nba108 = Graphics.loadImage("Nuclear Tileset\nuclaerba-108.png")
☢霊烏路空☢.nba109 = Graphics.loadImage("Nuclear Tileset\nuclaerba-109.png")
☢霊烏路空☢.nba115 = Graphics.loadImage("Nuclear Tileset\nuclaerba-115.png")
☢霊烏路空☢.nba116 = Graphics.loadImage("Nuclear Tileset\nuclaerba-116.png")
☢霊烏路空☢.nba118 = Graphics.loadImage("Nuclear Tileset\nuclaerba-118.png")
☢霊烏路空☢.nba120 = Graphics.loadImage("Nuclear Tileset\nuclaerba-120.png")
☢霊烏路空☢.nba172 = Graphics.loadImage("Nuclear Tileset\background-172.png")
☢霊烏路空☢.nbl2 = Graphics.loadImage("Nuclear Tileset\block-2.png")
☢霊烏路空☢.nbl4 = Graphics.loadImage("Nuclear Tileset\block-4.png")
☢霊烏路空☢.nbl5 = Graphics.loadImage("Nuclear Tileset\block-5.png")
☢霊烏路空☢.nbl21 = Graphics.loadImage("Nuclear Tileset\nuclearbl-21.png")
☢霊烏路空☢.nbl22 = Graphics.loadImage("Nuclear Tileset\nuclearbl-22.png")
☢霊烏路空☢.nbl23 = Graphics.loadImage("Nuclear Tileset\nuclearbl-23.png")
☢霊烏路空☢.nbl24 = Graphics.loadImage("Nuclear Tileset\nuclearbl-24.png")
☢霊烏路空☢.nbl30 = Graphics.loadImage("Nuclear Tileset\block-30.png")
☢霊烏路空☢.nbl34 = Graphics.loadImage("Nuclear Tileset\nuclearbl-34.png")
☢霊烏路空☢.nbl35 = Graphics.loadImage("Nuclear Tileset\nuclearbl-35.png")
☢霊烏路空☢.nbl36 = Graphics.loadImage("Nuclear Tileset\nuclearbl-36.png")
☢霊烏路空☢.nbl38 = Graphics.loadImage("Nuclear Tileset\nuclearbl-38.png")
☢霊烏路空☢.nbl69 = Graphics.loadImage("Nuclear Tileset\nuclearbl-69.png")
☢霊烏路空☢.nbl103 = Graphics.loadImage("Nuclear Tileset\nuclearbl-103.png")
☢霊烏路空☢.nbl104 = Graphics.loadImage("Nuclear Tileset\nuclearbl-104.png")
☢霊烏路空☢.nbl137 = Graphics.loadImage("Nuclear Tileset\nuclearbl-137.png")
☢霊烏路空☢.nbl140 = Graphics.loadImage("Nuclear Tileset\nuclearbl-140.png")
☢霊烏路空☢.nbl142 = Graphics.loadImage("Nuclear Tileset\nuclearbl-142.png")
☢霊烏路空☢.nbl145 = Graphics.loadImage("Nuclear Tileset\nuclearbl-145.png")
☢霊烏路空☢.nbl148 = Graphics.loadImage("Nuclear Tileset\nuclearbl-148.png")
☢霊烏路空☢.nbl149 = Graphics.loadImage("Nuclear Tileset\nuclearbl-149.png")
☢霊烏路空☢.nbl150 = Graphics.loadImage("Nuclear Tileset\nuclearbl-150.png")
☢霊烏路空☢.nbl151 = Graphics.loadImage("Nuclear Tileset\nuclearbl-151.png")
☢霊烏路空☢.nbl152 = Graphics.loadImage("Nuclear Tileset\nuclearbl-152.png")
☢霊烏路空☢.nbl154 = Graphics.loadImage("Nuclear Tileset\nuclearbl-154.png")
☢霊烏路空☢.nbl155 = Graphics.loadImage("Nuclear Tileset\nuclearbl-155.png")
☢霊烏路空☢.nbl156 = Graphics.loadImage("Nuclear Tileset\nuclearbl-156.png")
☢霊烏路空☢.nbl157 = Graphics.loadImage("Nuclear Tileset\nuclearbl-157.png")
☢霊烏路空☢.nbl158 = Graphics.loadImage("Nuclear Tileset\nuclearbl-158.png")
☢霊烏路空☢.nbl184 = Graphics.loadImage("Nuclear Tileset\nuclearbl-184.png")
☢霊烏路空☢.nbl415 = Graphics.loadImage("Nuclear Tileset\nuclearbl-415.png")
☢霊烏路空☢.nbl416 = Graphics.loadImage("Nuclear Tileset\nuclearbl-416.png")
☢霊烏路空☢.nbl417 = Graphics.loadImage("Nuclear Tileset\nuclearbl-417.png")
☢霊烏路空☢.nbl418 = Graphics.loadImage("Nuclear Tileset\nuclearbl-418.png")
☢霊烏路空☢.nbl419 = Graphics.loadImage("Nuclear Tileset\nuclearbl-419.png")
☢霊烏路空☢.nbl421 = Graphics.loadImage("Nuclear Tileset\nuclearbl-421.png")
☢霊烏路空☢.nbl422 = Graphics.loadImage("Nuclear Tileset\nuclearbl-422.png")
☢霊烏路空☢.nbl423 = Graphics.loadImage("Nuclear Tileset\nuclearbl-423.png")
☢霊烏路空☢.nbl424 = Graphics.loadImage("Nuclear Tileset\nuclearbl-424.png")
☢霊烏路空☢.nbl425 = Graphics.loadImage("Nuclear Tileset\nuclearbl-425.png")
☢霊烏路空☢.nbl426 = Graphics.loadImage("Nuclear Tileset\nuclearbl-426.png")
☢霊烏路空☢.nbl427 = Graphics.loadImage("Nuclear Tileset\nuclearbl-427.png")
☢霊烏路空☢.nbl436 = Graphics.loadImage("Nuclear Tileset\nuclearbl-436.png")
☢霊烏路空☢.nbl459 = Graphics.loadImage("Nuclear Tileset\block-459.png")
--☢霊烏路空☢.nef55 = Graphics.loadImage("Nuclear Tileset\effct-55.png")

--Actual Section Code
function onStartSection7()
	if Layout > 1 then
		Layout = rng.random();
	end
	if Layout == 1 then
		triggerEvent("MECHDRAGON777 - Danmaku")
	end
	if Layout == 2 then
		triggerEvent("MECHDRAGON777 - Anonymous")
	end
	if Layout == 3 then
		triggerEvent("MECHDRAGON777 - Radiation")
	end
	if Layout == 4 then
		triggerEvent("MECHDRAGON777 - Laser")
	end
end

function onLoopSection7()
    --Debug--
	--Text.print(Layout,0,0)
	--Little Boo's Screen--
	if Layout == 2 then
		Audio.MusicOpen("PvZ_2_-_NMT_-_8-Bit.ogg")
		Audio.MusicPlay()
	end
	-------------
	--Radiation--
	-------------
	if Layout == 3 then
	--graphics load
		Graphics.sprites.background[24] = ☢霊烏路空☢.nba24
		Graphics.sprites.background[57] = ☢霊烏路空☢.nba57
		Graphics.sprites.background[62] = ☢霊烏路空☢.nba62
		Graphics.sprites.background[66] = ☢霊烏路空☢.nba66
		Graphics.sprites.background[67] = ☢霊烏路空☢.nba67
		Graphics.sprites.background[69] = ☢霊烏路空☢.nba69
		Graphics.sprites.background[75] = ☢霊烏路空☢.nba75
		Graphics.sprites.background[76] = ☢霊烏路空☢.nba76
		Graphics.sprites.background[78] = ☢霊烏路空☢.nba78
		Graphics.sprites.background[79] = ☢霊烏路空☢.nba79
		Graphics.sprites.background[87] = ☢霊烏路空☢.nba87
		Graphics.sprites.background[95] = ☢霊烏路空☢.nba95
		Graphics.sprites.background[97] = ☢霊烏路空☢.nba97
		Graphics.sprites.background[99] = ☢霊烏路空☢.nba99
		Graphics.sprites.background[108] = ☢霊烏路空☢.nba108
		Graphics.sprites.background[109] = ☢霊烏路空☢.nba109
		Graphics.sprites.background[115] = ☢霊烏路空☢.nba115
		Graphics.sprites.background[116] = ☢霊烏路空☢.nba116
		Graphics.sprites.background[118] = ☢霊烏路空☢.nba118
		Graphics.sprites.background[120] = ☢霊烏路空☢.nba120
		Graphics.sprites.block[2] = ☢霊烏路空☢.nbl2
		Graphics.sprites.block[4] = ☢霊烏路空☢.nbl4
		Graphics.sprites.block[5] = ☢霊烏路空☢.nbl5
		Graphics.sprites.block[21] = ☢霊烏路空☢.nbl21
		Graphics.sprites.block[21] = ☢霊烏路空☢.nbl22
		Graphics.sprites.block[21] = ☢霊烏路空☢.nbl23
		Graphics.sprites.block[21] = ☢霊烏路空☢.nbl24
		Graphics.sprites.block[30] = ☢霊烏路空☢.nbl30
		Graphics.sprites.block[34] = ☢霊烏路空☢.nbl34
		Graphics.sprites.block[35] = ☢霊烏路空☢.nbl35
		Graphics.sprites.block[36] = ☢霊烏路空☢.nbl36
		Graphics.sprites.block[69] = ☢霊烏路空☢.nbl69
		Graphics.sprites.block[103] = ☢霊烏路空☢.nbl103
		Graphics.sprites.block[104] = ☢霊烏路空☢.nbl104
		Graphics.sprites.block[137] = ☢霊烏路空☢.nbl137
		Graphics.sprites.block[140] = ☢霊烏路空☢.nbl140
		Graphics.sprites.block[142] = ☢霊烏路空☢.nbl142
		Graphics.sprites.block[145] = ☢霊烏路空☢.nbl145
		Graphics.sprites.block[148] = ☢霊烏路空☢.nbl148
		Graphics.sprites.block[149] = ☢霊烏路空☢.nbl149
		Graphics.sprites.block[150] = ☢霊烏路空☢.nbl150
		Graphics.sprites.block[151] = ☢霊烏路空☢.nbl151
		Graphics.sprites.block[152] = ☢霊烏路空☢.nbl152
		Graphics.sprites.block[154] = ☢霊烏路空☢.nbl154
		Graphics.sprites.block[155] = ☢霊烏路空☢.nbl155
		Graphics.sprites.block[156] = ☢霊烏路空☢.nbl156
		Graphics.sprites.block[157] = ☢霊烏路空☢.nbl157
		Graphics.sprites.block[158] = ☢霊烏路空☢.nbl158
		Graphics.sprites.block[184] = ☢霊烏路空☢.nbl184
		Graphics.sprites.block[415] = ☢霊烏路空☢.nbl415
		Graphics.sprites.block[416] = ☢霊烏路空☢.nbl416
		Graphics.sprites.block[417] = ☢霊烏路空☢.nbl418
		Graphics.sprites.block[419] = ☢霊烏路空☢.nbl419
		Graphics.sprites.block[421] = ☢霊烏路空☢.nbl421
		Graphics.sprites.block[422] = ☢霊烏路空☢.nbl422
		Graphics.sprites.block[423] = ☢霊烏路空☢.nbl423
		Graphics.sprites.block[424] = ☢霊烏路空☢.nbl424
		Graphics.sprites.block[425] = ☢霊烏路空☢.nbl425
		Graphics.sprites.block[426] = ☢霊烏路空☢.nbl426
		Graphics.sprites.block[427] = ☢霊烏路空☢.nbl427
		Graphics.sprites.block[436] = ☢霊烏路空☢.nbl436
		Graphics.sprites.block[459] = ☢霊烏路空☢.nbl459
--		Graphics.sprites.effect[55] = ☢霊烏路空☢.nef459
	--Audio
		Audio.MusicOpen("Touhou Genso Rondo (PS4) - Utsuho's Theme.ogg")
		Audio.MusicPlay()
	--Radiation Damage
	local intersectingBgos = BGO.getIntersecting(player.x, player.y, player.x + player.width, player.y + player.height)
	for _, q in pairs(intersectingBgos) do
        if biohazard == 0 and playerDead == false then
            if q.id == 66 or q.id == 172 then
                metre = metre + 0.08
            end
            if q.id == 24 then
                metre = metre + 0.16
            end
            if q.id ~= 66 and q.id ~= 24 and metre >= 0 and q.id ~= 172 or #intersectingBgos == 0 then
                metre = metre - 0.005
            end
        end
	end
	if (player:mem(0x13E, FIELD_WORD) ~= 0) then
		PlayerDead = true
	end
	--Meter
		if(metre >= 0) then
			Graphics.drawImageWP(radiationbar, 335, 81, 2)
			if(metre >= 5) then
				Graphics.drawImageWP(radiationpoint, 367, 81, 3)
				if(metre >= 10) then
					Graphics.drawImageWP(radiationpoint, 371, 81, 3)
					if(metre >= 15) then
						Graphics.drawImageWP(radiationpoint, 375, 81, 3)
						if(metre >= 20) then
							Graphics.drawImageWP(radiationpoint, 379, 81, 3)
							if(metre >= 25) then
								Graphics.drawImageWP(radiationpoint, 383, 81, 3)
								if(metre >= 30) then
									Graphics.drawImageWP(radiationpoint, 387, 81, 3)
									if(metre >= 35) then
										Graphics.drawImageWP(radiationpoint, 391, 81, 3)
										if(metre >= 40) then
											Graphics.drawImageWP(radiationpoint, 395, 81, 3)
											if(metre >= 45) then
												Graphics.drawImageWP(radiationpoint, 399, 81, 3)
												if(metre >= 50) then
													Graphics.drawImageWP(radiationpoint, 403, 81, 3)
													if(metre >= 55) then
														Graphics.drawImageWP(radiationpoint, 407, 81, 3)
														if(metre >= 60) then
															Graphics.drawImageWP(radiationpoint, 411, 81, 3)
															if(metre >= 65) then
																Graphics.drawImageWP(radiationpoint, 415, 81, 3)
																if(metre >= 70) then
																	Graphics.drawImageWP(radiationpoint, 419, 81, 3)
																	if(metre >= 75) then
																		Graphics.drawImageWP(radiationpoint, 423, 81, 3)
																		if(metre >= 80) then
																			Graphics.drawImageWP(radiationpoint, 427, 81, 3)
																			if(metre >= 85) then
																				Graphics.drawImageWP(radiationpoint, 431, 81, 3)
																				if(metre >= 90) then
																					Graphics.drawImageWP(radiationpoint, 435, 81, 3)
																					if(metre >= 95) then
																						Graphics.drawImageWP(radiationpoint, 439, 81, 3)
																						if(metre >= 100) then
																							Graphics.drawImageWP(radiationpoint, 443, 81, 3)
																						end
																					end
																				end
																			end
																		end
																	end
																end
															end
														end
													end
												end
											end
										end
									end
								end
							end
						end
					end
				end
			end
		end
	end
end

function onEvent(Eventname)
	if Eventname == "MECHDRAGON777 - Anonymous" then
		Layer.get("MECHDRAGON777 - Anonymous")
		Layer:show(hideSmoke)
		Layer.get("MECHDRAGON777 - Danmaku")
		Layer:hide(hideSmoke)
		Layer.get("MECHDRAGON777 - Radiation")
		Layer:hide(hideSmoke)
		Layer.get("MECHDRAGON777 - Laser")
		Layer:hide(hideSmoke)
	end
end

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 14, 2016 5:10 am
by Hoeloe
MECHDRAGON777 wrote: I was wondering why the block swap was not working...
Using unicode symbols in variable names is an AWFUL idea. That may well be at least part of your problem.

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 14, 2016 5:13 am
by S1eth
Enjl wrote:
PixelPest wrote:
S1eth wrote:
Don't you just do this?

Code: Select all

local myBlock = Block.spawn(number blockId, number x, number y)
myBlock.layerName = "myLayerName" --this?  
myBlock.layerObj = Layer.get("myLayerName") --or this  (or both?) 
Given, I've never needed to spawn any blocks. That code is just what looking at the API page for 10 seconds got me.
You can define the layer as:

Code: Select all

local myLayerName = Layer(#)
Replace number with the number the layer is in the list. (Default layer is 0.)
myLayerName also shouldn't be in quotes since it's a variable
No. What S1eth wrote is correct. And I think you can write to layerName and layerObj.
layerName requires a VB6Str (String layername)
layerObj requires the layer object. Essentially what you wanted to assign to layerName in your post.
I tried it, and as Nerx said, both of these are readonly.
A newly spawned block returns "Default" as its layerName.
So, since these are readonly, and the Block.spawn funtion does not have an overload which accepts the layer as argument, it should be impossible to spawn a block on any layer other than "Default" until someone writes another Block.spawn function.

Maybe the Block:mem function can be used to circumvent this if you know the memory address of layerName and layerObj.
MECHDRAGON777 wrote: Graphics.sprites.background[24] = ☢霊烏路空☢.nba24
As per http://wohlsoft.ru/pgewiki/SpriteOverride_%28class%29 you shouldn't be replacing the background[24] itself.

Graphics.sprites.background[24].img = myLuaImageResource
MECHDRAGON777 wrote: So I should not use my username in my lua variable names? Thought we had to in relay levels...
Use "mechdragon"

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 14, 2016 5:18 am
by MECHDRAGON777
Hoeloe wrote:
MECHDRAGON777 wrote: I was wondering why the block swap was not working...
Using unicode symbols in variable names is an AWFUL idea. That may well be at least part of your problem.
So I should not use my username in my lua variable names? Thought we had to in relay levels...

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 14, 2016 5:32 am
by Hoeloe
MECHDRAGON777 wrote:Thought we had to in relay levels...
Use "MECHDRAGON" or something. Unicode symbols can seriously break your code.

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 14, 2016 7:50 am
by Emral
Wouldn't wrapping the replacement lines into a for loop be more efficient/readable/easier to edit? Something like:

Code: Select all

local tableOfBGOSpriteIDs = {1,3,6,8,99} --table of image IDs to import

for _,v in ipairs(tableOfBGOSpriteIDs) do
   local imageFile = Graphics.loadImage("MECHDRAGON.nba" .. tostring(v)..".png") --if you need the imageFile reference later, make imageFile a table outside the loop and set/get imageFile[v] inside the loop.
   Graphics.sprites.background[v].img = imageFile
end

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 14, 2016 12:52 pm
by Hoeloe
Enjl wrote:Wouldn't wrapping the replacement lines into a for loop be more efficient/readable/easier to edit?

Yes it would.

In future, Mechdragon, if you find yourself needing to make a bunch of variables for a similar thing, particularly if you're finding yourself naming them something like: "name1", "name2", "name3", etc., consider whether or not it would be easier to just use a table.

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 14, 2016 1:35 pm
by Kevsoft
Enjl wrote:
PixelPest wrote:
S1eth wrote:
Don't you just do this?

Code: Select all

local myBlock = Block.spawn(number blockId, number x, number y)
myBlock.layerName = "myLayerName" --this?  
myBlock.layerObj = Layer.get("myLayerName") --or this  (or both?) 
Given, I've never needed to spawn any blocks. That code is just what looking at the API page for 10 seconds got me.
You can define the layer as:

Code: Select all

local myLayerName = Layer(#)
Replace number with the number the layer is in the list. (Default layer is 0.)
myLayerName also shouldn't be in quotes since it's a variable
No. What S1eth wrote is correct. And I think you can write to layerName and layerObj.
layerName requires a VB6Str (String layername)
layerObj requires the layer object. Essentially what you wanted to assign to layerName in your post.
The reason why the layerName is read-only is because it would require to update the visiblity flag of the object (If the item is visible, but the layer is hidden, then the item must be hidden too)

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 14, 2016 1:55 pm
by Hoeloe
Kevsoft wrote: The reason why the layerName is read-only is because it would require to update the visiblity flag of the object (If the item is visible, but the layer is hidden, then the item must be hidden too)
That's... kind of a poor reason in my opinion. You could quite easily set it up to automatically update the visibility of the item when you set the layerName value, or you could just add a note on the documentation.

Besides, I believe you can set the layer name via mem calls anyway.

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 14, 2016 2:15 pm
by Kevsoft
Hoeloe wrote:
That's... kind of a poor reason in my opinion. You could quite easily set it up to automatically update the visibility of the item when you set the layerName value, or you could just add a note on the documentation.

Besides, I believe you can set the layer name via mem calls anyway.
I know that it is a poor reason, and it will change. I already put it on the wishlist so I won't forget it.

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 14, 2016 5:55 pm
by HenryRichard
Is there a way to use multi-channel music?

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 14, 2016 6:15 pm
by MECHDRAGON777
Hoeloe wrote:
Enjl wrote:Wouldn't wrapping the replacement lines into a for loop be more efficient/readable/easier to edit?

Yes it would.

In future, Mechdragon, if you find yourself needing to make a bunch of variables for a similar thing, particularly if you're finding yourself naming them something like: "name1", "name2", "name3", etc., consider whether or not it would be easier to just use a table.
I should learn more about tables.