Ah, look. They are different folders. The main.lua I was referring is inside editor folder. tilemap.lua is in game folder.Cryogenical wrote:megalukes wrote: In your main, typeCode: Select all
require "game/tilemap"
"Questions that don't deserve their own thread" thread
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: "Questions that don't deserve their own thread" thread
Re: "Questions that don't deserve their own thread" thread
Try this:
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)
Code: Select all
require "../game/tilemap"
(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
Nope, it didn't workPlu wrote:Try this:
That should work.Code: Select all
require "../game/tilemap"
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.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)
- 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
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".Plu wrote:Try this:
That should work.Code: Select all
require "../game/tilemap"
Now note that while using slashes in module names is accepted, it is technically wrong.
- 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
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.
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?
Code: Select all
function clamp(val, low, high)
return (val > high and high) or (val < low and low) or val
end
- 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
The answer is that and and or are short-circuit operators. This means that they are roughly equivalent to: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?
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
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.
- 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
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
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
- 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
If they both are true, then yes.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.
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()).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.
Help us help you: attach a .love.
Re: "Questions that don't deserve their own thread" thread
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.
- 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
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 So here I'm retyping another.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.
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
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 7 guests