Page 1 of 1

Another lua question!

Posted: 19 Oct 2009, 08:39
by Tribulex
Thank you for solving my first problem. Here is my second problem:

I have a texture and a config value with 4 values. For clarity lets call those values north, east, south, and west.

These values will divide the texture into a 3x3 grid, where the first row is north pixels high, last row is south pixels high, first column is west pixels wide, and the last column is east pixels wide. I want to be able to draw these textures on the screen individually, and i want to do so with scaling.

basically, it so I can make a texture for the background of a gui element with the borders scaling correctly.


sorry for english,
d_b



OLD POST:



I have this table:

Code: Select all

local morphDefs = {
    ant= {
        [1] = {into = 'mantis', metal = 100, energy = 0, time = 5,},
    },
    ...
}
I want to turn it into this:

Code: Select all

{
    [1] = {[2], 100}, 
    ...
}
where 1 is the udef id of 'ant' and 2 is udef id of 'mantis' and 100 is the metal characteristic. Can someone write some code to do this?

Pie and cake,
d_b

Re: Incredibly confused and frustrated as usual [TABLES/ARRAYS]

Posted: 19 Oct 2009, 14:54
by AF
So you want an array of tables? Aren't tables and arrays the same thing in lua?

Re: Incredibly confused and frustrated as usual [TABLES/ARRAYS]

Posted: 19 Oct 2009, 15:29
by lurker
Wow, you wrote that confusingly.

Code: Select all

pieCakeDefs = {}
for defName, mDef in pairs(morphDefs) do
   local defID = UnitDefNames[defName].id
   local intoID = UnitDefNames[mDef.into].id
   pieCakeDefs[defID] = {intoID, mDef.metal}
end
Note that this code will crash if you have any names wrong. Adding error checking is left as an exercise to the reader.

Re: Incredibly confused and frustrated as usual [TABLES/ARRAYS]

Posted: 19 Oct 2009, 22:55
by Tribulex
i dont know what to do to convey to everyone including yourself that you are epically awesome mr. lurker. pie and cake!!!!

Re: Incredibly confused and frustrated as usual [TABLES/ARRAYS]

Posted: 19 Oct 2009, 23:00
by Tribulex
lurker wrote:Wow, you wrote that confusingly.

Code: Select all

pieCakeDefs = {}
for defName, mDef in pairs(morphDefs) do
   local defID = UnitDefNames[defName].id
   local intoID = UnitDefNames[mDef.into].id
   pieCakeDefs[defID] = {intoID, mDef.metal}
end
Note that this code will crash if you have any names wrong. Adding error checking is left as an exercise to the reader.

wait wait wait this wont work for this:

Code: Select all

local morphDefs = {
    ant= {
        [1] = {into = 'mantis', metal = 100, energy = 0, time = 5,},
        [2] = {into = 'anklet', metal = 200, energy = 0, time = 5,},
        [3] = {into = 'aviantor', metal = 300, energy = 0, time = 5,},
        [4] = {into = 'dirigantible', metal = 400, energy = 0, time = 5,},
    },
    ...
}

Re: Incredibly confused and frustrated as usual [TABLES/ARRAYS]

Posted: 19 Oct 2009, 23:16
by Argh

Code: Select all

local morphDefs = {
    ant= {
        [1] = {into = UnitDefNames[mantis].id, metal = 100, energy = 0, time = 1},
    },
    ...
}

Re: Incredibly confused and frustrated as usual [TABLES/ARRAYS]

Posted: 20 Oct 2009, 04:20
by lurker
Yeah, I tend to do that when I'm not paying attention. My code only supports single-option morphs. I did make a mistake in reading your code, because it looks like you're asking for something that doesn't work.

You want this when you only have a single option, right?

Code: Select all

{
    ant-id = {into-id, 100}, 
    ...
}
So, if you have multiple morphs:

Code: Select all

{
    ant-id = {into-id-1, 100},
    ant-id = {into-id-2, 100}, 
    ...
}
Which just overwrites the first one with the second one.


Unless you actually want:

Code: Select all

{
    ant-id = {
        {into-id-1, 100},
        {into-id-2, 100}, 
    }
    ...
}
Please show me what you want your output to look like *with multiple morph options*.
And I'm not sure what Argh's doing.

Re: Incredibly confused and frustrated as usual [TABLES/ARRAYS]

Posted: 20 Oct 2009, 04:22
by Tribulex
lurker wrote:Yeah, I tend to do that when I'm not paying attention. My code only supports single-option morphs. I did make a mistake in reading your code, but that's because I can't tell what you want.
You want this, right?

Code: Select all

{
    ant-id = {into-id, 100}, 
    ...
}
So, if you have multiple morphs:

Code: Select all

{
    ant-id = {into-id-1, 100},
    ant-id = {into-id-2, 100}, 
    ...
}
Which just overwrites the first one with the second one.

Unless you actually want:

Code: Select all

{
    ant-id = {
        {into-id-1, 100},
        {into-id-2, 100}, 
    }
    ...
}
Please show me what you want your output to look like *with multiple morph options*.
And I'm not sure what Argh's doing.
I want the second please. No one knows what argh's doing.

Re: Incredibly confused and frustrated as usual [TABLES/ARRAYS]

Posted: 20 Oct 2009, 04:26
by lurker

Code: Select all

pieCakeDefs = {}
for defName,morphs in pairs(morphDefs) do
   local defID = UnitDefNames[defName].id
   local cake = {}

   for i, mDef in ipairs(morphs) do
      local intoID = UnitDefNames[mDef.into].id
      cake[i] = {intoID, mDef.metal}
   end
   pieCakeDefs[defID] = cake

end

Re: Incredibly confused and frustrated as usual [TABLES/ARRAYS]

Posted: 20 Oct 2009, 22:23
by Tribulex
lurker wrote:

Code: Select all

pieCakeDefs = {}
for defName,morphs in pairs(morphDefs) do
   local defID = UnitDefNames[defName].id
   local cake = {}

   for i, mDef in ipairs(morphs) do
      local intoID = UnitDefNames[mDef.into].id
      cake[i] = {intoID, mDef.metal}
   end
   pieCakeDefs[defID] = cake

end
Thank you very much...

Re: New Lua Problem that i have no clue how to approach

Posted: 23 Oct 2009, 04:12
by Tribulex
i updated the first post btw. I need a way of displaying a rectangular section of a texture. People keep saying "texrect" and then ignoring me, but thats not what i need. I want to display a fragment or part of the texture which is rectangular, not the whole texture.

Thank you.

Re: New Lua Problem that i have no clue how to approach

Posted: 23 Oct 2009, 11:07
by Argh
TexRect accepts texture coordinates as parameters you're allowed to pass (try to imagine texture coordinates as an arbitrary quad you place over your texture, even outside its bounds). This will allow you to build your offset and show a non-square area sample from a texture.

So, for example, gl.TexRect(0,0,600,600,0,0,0.5,0.5) would render your TexRect with one quarter of your texture used to cover the whole quad.

Anyhow, hope that helps.

Re: New Lua Problem that i have no clue how to approach

Posted: 23 Oct 2009, 23:46
by Tribulex
Argh wrote:TexRect accepts texture coordinates as parameters you're allowed to pass (try to imagine texture coordinates as an arbitrary quad you place over your texture, even outside its bounds). This will allow you to build your offset and show a non-square area sample from a texture.

So, for example, gl.TexRect(0,0,600,600,0,0,0.5,0.5) would render your TexRect with one quarter of your texture used to cover the whole quad.

Anyhow, hope that helps.
YAY SUPER SUPER HELPFUL GUY!!!!!!!!! YOU WIN!!!!!!!!!!

Re: Another lua question!

Posted: 24 Oct 2009, 10:33
by Tribulex
How do i translate this command in cmdcolors.txt:

Code: Select all

alwaysDrawQueue   1
into something i can control in my mod. I would imagine there is some lua trickery that can help, but i don't know. Can someone give help/advice please?