Page 20 of 91

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

Posted: Fri Sep 12, 2014 7:43 pm
by megalukes
Cryogenical wrote:
megalukes wrote: In your main, type

Code: Select all

require "game/tilemap"
Ah, look. They are different folders. The main.lua I was referring is inside editor folder. tilemap.lua is in game folder.

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

Posted: Fri Sep 12, 2014 8:24 pm
by Plu
Try this:

Code: Select all

require "../game/tilemap"
That should work.

(Sidenote: your main.lua should be in the main folder, this setup isn't going to work when you try to distribute the game)
(Unless they're two different projects)

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

Posted: Fri Sep 12, 2014 8:34 pm
by megalukes
Plu wrote:Try this:

Code: Select all

require "../game/tilemap"
That should work.
Nope, it didn't work :(
Plu wrote: (Sidenote: your main.lua should be in the main folder, this setup isn't going to work when you try to distribute the game)
(Unless they're two different projects)
Ah, thanks, I didn't know that. I don't have to worry here because the "editor" thing is just a tile/object editor I and my team are going to use.

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

Posted: Fri Sep 12, 2014 9:08 pm
by bartbes
Plu wrote:Try this:

Code: Select all

require "../game/tilemap"
That should work.
No it won't. Let me explain. Require takes module names, these are distinct to paths. One can turn a module name into a path by replacing all dots by slashes, then appending either '.lua' or '/init.lua'. If either exists, require succeeds, if not, it looks at other sources that can provide the module name (which again, isn't a path, which makes this possible in the first place). Applying this, your require statement would look for "///game/tilemap.lua".

Now note that while using slashes in module names is accepted, it is technically wrong.

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

Posted: Sat Sep 13, 2014 3:46 am
by Zilarrezko
I saw, I think it was in this thread, or somewhere, someone used this method for returning values. It was confusing, but I understand the structure enough to have implemented it into clamp.

Code: Select all

function clamp(val, low, high)
	return (val > high and high) or (val < low and low) or val
end
The thing I don't understand is why it doesn't return the conditional's boolean, and only the value. And I do realize that I don't need the parenthesis, and that if I switch the conditional with the value, it returns only the conditional. So I guess my question, more simply, Is; why does the function only return the data on the right side of the and statement?

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

Posted: Sat Sep 13, 2014 9:22 am
by Robin
Zilarrezko wrote:So I guess my question, more simply, Is; why does the function only return the data on the right side of the and statement?
The answer is that and and or are short-circuit operators. This means that they are roughly equivalent to:

Code: Select all

function and(a, b)
    if a then
        return b
    else
        return a
    end
end

function or(a, b)
    if a then
        return a
    else
        return b
    end
end
Try it out in your head, think about what happens if you pass true or false to those functions (there are four possibilities to think about).

Then we look at clamp. There are three cases here: high < val, val < low and low <= val <= high, so let's see what happens:

Code: Select all

-- high < val
((true and high) or ?) or ?
(high or ?) or ? -- numbers always evaluate to true
high or ?
high

-- val < low
((false and high) or ?) or ?
(false or ?) or ?
? or ? -- welp now we need the value of the first ?
(true and low) or ?
low or ? -- numbers always truthy
low

--low <= val <= high
((false and high) or ?) or ?
(false or ?) or ?
? or ? -- welp now we need the value of the first ?
(false and low) or ?
false or ?
? -- now we need the value of the second ?
val

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

Posted: Sat Sep 13, 2014 10:38 am
by Zilarrezko
Alright, so if I have 2 ands (2 conditionals and a value) in order of "return conditional and conditional and value" It will return the value, just because it's the last one.

Kinda like as it's going through the and's it's pushing the conditional result/value to a stack, then at the end, if the conditionals are all true (and the values are not nil) in the stack, then it will pop the value on top of the stack and return it.

Very good, thanks

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

Posted: Sat Sep 13, 2014 11:07 am
by Robin
Zilarrezko wrote:Alright, so if I have 2 ands (2 conditionals and a value) in order of "return conditional and conditional and value" It will return the value, just because it's the last one.
If they both are true, then yes.
Zilarrezko wrote:Kinda like as it's going through the and's it's pushing the conditional result/value to a stack, then at the end, if the conditionals are all true (and the values are not nil) in the stack, then it will pop the value on top of the stack and return it.
I guess? Not really? If it helps you understand it, sure. But remember that (false and error()) will not error, and neither will (true or error()).

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

Posted: Sat Sep 13, 2014 3:46 pm
by ELFUERTE
Hey it's me again. You guys helped me solve that problem,maybe you can help me again. So I'm using advanced tile loader,and to move my character I use the function moveTile wich,obviusly, moves my character of a single tile unit. Since the user must move the character,I've used the .isDown function. But ,the character moves waaaaaaaaaaaaaaay too fast now. Link to the love file. PLEASE NOTE:DOUBLE CLICKING THE LOVE FILE WONT WORK. IF YOU EXTRACT THE CODE AND RUN IT TROUGHT LOVE.EXE TOUGH,IT WORKS.

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

Posted: Sat Sep 13, 2014 8:30 pm
by Zilarrezko
ELFUERTE wrote:Hey it's me again. You guys helped me solve that problem,maybe you can help me again. So I'm using advanced tile loader,and to move my character I use the function moveTile wich,obviusly, moves my character of a single tile unit. Since the user must move the character,I've used the .isDown function. But ,the character moves waaaaaaaaaaaaaaay too fast now. Link to the love file. PLEASE NOTE:DOUBLE CLICKING THE LOVE FILE WONT WORK. IF YOU EXTRACT THE CODE AND RUN IT TROUGHT LOVE.EXE TOUGH,IT WORKS.
Okay, I just wrote an entire essay explaining something wrong with something you didn't want fixed and that didn't have to do with anything you asked for. And whan I tried to fix what I thought you wanted, I realized it wasn't what the problem was :cry: So here I'm retyping another.

Alrighty! So your problem that you want fixed is in your mobs.lua file in the boy.keypressed function... There are two possible fixes, depending on how you want to implement them. I'll create two variations of the "Boy.keypressed" functions. But here i'll explain them.

First: You can keep the style you were going for in the first one. Moving the player without having to lift up the key per interval (you were doing it per frame in the treeLevel file, that's why he was moving very fast). To accomplish this, I put a Boy.movementTimer and Boy.movementTimerLimit at the top of mobs.lua. Then every frame when it calls the Boy.Update(dt) I put in the love.update function, it will add dt to Boy.movementTimer, and when Boy.movementTimer is greater than Boy.movementTimerLimit, it will move the player if the keys that move the player are down, then subtracting Boy.movementTimerLimit to Boy.movementTimer so that way there's a consistent update, so that way you won't get 2 updates in one second, and 1 update in another second (not very consistent, but it makes me feel special).

Second: You can go with what you had in the main.lua's love.keypressed, and do key presses instead of checking to see if a button is down every timer interval. You will have to press a key everytime you want to move, but it's the simplest implication.

Here's the .love's. Choose, your, path