Page 9 of 91

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Aug 23, 2014 3:57 pm
by Whatthefuck
I want to give a shot at computing the lighting via a shader and was wondering if there's a way to get the colors of another pixel (in whatever direction) ?

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Aug 23, 2014 8:10 pm
by IceQB
I have little question, how to make something work only for all numbers more from n?
For example:

Code: Select all

egg = {1,2.3.4,5}
n = 2

--egg 3,4 and 5 do /something/

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Aug 23, 2014 8:21 pm
by dusoft
IceQB wrote:I have little question, how to make something work only for all numbers more from n?
For example:

Code: Select all

egg = {1,2.3.4,5}
n = 2

--egg 3,4 and 5 do /something/

Code: Select all

if egg>2 then do...

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Aug 23, 2014 8:30 pm
by Robin
Does n refer to index or value?

If the former, I'd use a numeric for loop:

Code: Select all

for i = n + 1, #egg do
 --- do something with egg[i]
end
otherwise it's a bit more complicated and it depends on a lot of things what the best way to go about it would be. (Probably either looking up the index with binary search, or building a reverse-lookup table beforehand.)

Re: "Questions that don't deserve their own thread" thread

Posted: Sun Aug 24, 2014 11:40 pm
by IceQB
Thanks Robin, It is it what I was looking for.

Re: "Questions that don't deserve their own thread" thread

Posted: Mon Aug 25, 2014 1:51 am
by lumlune
Question on optional args...

Code: Select all

wordbank = { }
function wordbank.init()
    wordbank.activate("goosanders", "optional flag")
end

function wordbank.activate(selection, ...)
    for idx, flag in ipairs(arg) do
        print(flag)
        -- e.g. "optional flag" prints here
    end
end

wordbank.init()
In its own script apart from LÖVE, this works. In my project it does not, printing this instead.

Code: Select all

%project path% love.exe
embedded boot.lua
What does LÖVE do differently?

Re: "Questions that don't deserve their own thread" thread

Posted: Mon Aug 25, 2014 2:16 am
by DaedalusYoung
LÖVE uses LuaJIT, based on Lua 5.1, which doesn't use arg anymore.

Change this:

Code: Select all

for idx, flag in ipairs(arg) do
to this:

Code: Select all

for idx, flag in ipairs(...) do
[edit] See also this topic.

Re: "Questions that don't deserve their own thread" thread

Posted: Mon Aug 25, 2014 2:47 am
by lumlune
Thank you. :awesome:

Re: "Questions that don't deserve their own thread" thread

Posted: Mon Aug 25, 2014 4:55 am
by Zilarrezko
I'm putting my question here because I think I'm starting to clutter stuff up with my own topics.

So I've been working with 3D for the past few weeks. Mostly looking forward into concepts that I'll need in the future.

I've watch oysi's videos of course, but I wanted to walk myself forward without watching a tutorial and it seems I've hit a snag on something several times in the same spot. and of all things I believe it's either tables confusing me (A lot of tables within tables), or I'm doing something that lua can't do.

The problem is in my algorithm at line 44

and bonus points to whoever can get the model loader to recognize 3 vertex face from a 4 vertex face and run the proper one and not both.

PS. Very inefficient, yet functional shunting yard algorithm in there with reverse polish notation calculator too.

Re: "Questions that don't deserve their own thread" thread

Posted: Mon Aug 25, 2014 8:09 am
by bartbes
DaedalusYoung wrote:

Code: Select all

for idx, flag in ipairs(...) do
You mean

Code: Select all

for idx, flag in ipairs({...}) do
or

Code: Select all

for idx, flag in ipairs{...} do