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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Locked
User avatar
megalukes
Citizen
Posts: 94
Joined: Fri Jun 27, 2014 11:29 pm
Location: Brazil

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

Post 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.
Attachments
editor2.png
editor2.png (35.98 KiB) Viewed 3280 times
editor1.png
editor1.png (20.02 KiB) Viewed 3280 times
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

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

Post 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)
User avatar
megalukes
Citizen
Posts: 94
Joined: Fri Jun 27, 2014 11:29 pm
Location: Brazil

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

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post 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.
User avatar
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

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

Post 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?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post 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
Help us help you: attach a .love.
User avatar
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

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

Post 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
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post 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()).
Help us help you: attach a .love.
ELFUERTE
Prole
Posts: 7
Joined: Fri Sep 12, 2014 2:29 pm

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

Post 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.
User avatar
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

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

Post 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
Attachments
Second.love
(91.7 KiB) Downloaded 109 times
First.love
(91.78 KiB) Downloaded 115 times
Locked

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 7 guests