• What do you need help with? Version 5
    5,752 replies, posted
Working with Love2D at the moment, having a weird error when running this simple code. This is my main.lua file: [code]require "camera.lua" require "timer.lua" function love.load() love.graphics.setBackgroundColor(50, 80, 255) love.graphics.setMode(640, 480, false, true, 0) camera:set() end function love.update(dt) timer:update --keyboard input if love.keyboard.isDown('d') then camera.move(1 * dt, 0) end if love.keyboard.isDown("a") then camera.move(-1 * dt, 0) end if love.keyboard.isDown("w") then camera.move(0, -1 * dt) end if love.keyboard.isDown("s") then camera.move(0, 1 * dt) end if love.keyboard.isDown("e") then camera.rotate(1 * dt) end if love.keyboard.isDown("q") then camera.rotate(-1 * dt) end end function love.draw() camera:set() --draw game camera:unset() --draw HUD end [/code] This is my timer.lua file: [code] timer = {} local time = 0 function timer.update() time = time + 1 end function timer.getTime() return time end [/code] This is my camera.lua file: [code]camera = {} camera.x = 0 camera.y = 0 camera.scaleX = 1 camera.scaleY = 1 camera.rotation = 0 function camera.set() love.graphics.push() love.graphics.translate(640/2, 480/2) love.graphics.rotate(-camera.rotation) love.graphics.translate(-(640/2), -(480/2)) love.graphics.scale(1 / camera.scaleX, 1 / camera.scaleY) love.graphics.translate(-camera.x, -camera.y) end function camera.unset() love.graphics.pop() end function camera.move(dx, dy) camera.x = camera.x + (dx or 0) camera.y = camera.y + (dy or 0) end function camera.rotate(dr) camera.rotation = camera.rotation + dr end function camera.scale(sx, sy) sx = sx or 1 camera.scaleX = camera.scaleX * sx camera.scaleY = camera.scaleY * (sy or sx) end function camera.setPosition(x, y) camera.x = x or camera.x camera.y = y or camera.y end function camera.setScale(sx, sy) camera.scaleX = sx or camera.scaleX camera.scaleY = sy or camera.scaleY end[/code] I'm getting this error: [IMG]http://i.imgur.com/Phihp.png[/IMG] And when I comment out the timer.lua stuff I get this one: [IMG]http://i.imgur.com/qr6nQ.png[/IMG] Just updated to Love 0.8.0 if that helps. What's up? [b]Fixed:[/b] Derp. Apparently require statements don't need the .lua extension in Love 0.8.0.
Line 13 of main.lua: [code]timer:update[/code] You are missing the parentheses and function arguments.
[QUOTE=MakeR;37053833]Line 13 of main.lua: [code]timer:update[/code] You are missing the parentheses and function arguments.[/QUOTE] That too. :\
[QUOTE=Pelf;37051187]My notepad program has a settings screen. On the bottom of the main screen there is a status bar which says things like "File Opened" when you open a file and similar things for other actions. I want to make it say "Settings Saved" when the user presses the save button on the settings form but I can't figure out how to do it. ... This is probably a stupid question but I have no idea what to do.[/QUOTE] You should try making your settings window modal, and then doing something like this when you want to show it: [code] SettingsForm.showDialog(); //do stuff with the settings NotepadForm.statusStripState.Text = ("Settings saved!"); [/code] That way, until the user clicks the 'Save' button (or closes the form), the label will get updated (since the settings form is modal, it'll stop all the code after it from being run (until it's closed)) This is untested, but it should work.
I want to write an Inter-Quake Export library in C# and need a valid file for testing and clarification. I have the mrfixit.iqm from the SDK, so where can I find either a compiled converter for Windows or an Inter-Quake Export file that uses as many features as possible?
Okay, can someone explain to me why this doesn't work? I want to be able to create a Room, then call draw() on each individual room that I create, but I Just can't get my head around what it wants from me. [code]Room = {} defaultWallTexture = love.graphics.newImage('images/wall_default.png') function Room.new(position_x, position_y, width, height) local room = {} room.pos_x = position_x room.pos_y = position_y room.size_x = width room.size_y = height --room.quad = love.graphics.newQuad(pos_x, pos_y, size_x, size_y, 2, 2) return room end function room.draw() love.graphics.rectangle('line', room.pos_x, room.pos_y, room.size_x, room.size_y) --love.graphics.drawq(defaultWallTexture, quad, pos_x, pos_y, 0, 1, 1, 0, 0, 1, 1) end[/code]
[QUOTE=T3hGamerDK;37032987]I'm a bit confused about this, and I couldn't find anything on this when I searched for it, so I'm going to ask here (I hope it's not the wrong section) For BareMetal OS .app programming, how do I copy the app files to the BareMetal node?[/QUOTE] .. Anyone? :(
[QUOTE=ConTron123;37055039]You should try making your settings window modal, and then doing something like this when you want to show it: [code] SettingsForm.showDialog(); //do stuff with the settings NotepadForm.statusStripState.Text = ("Settings saved!"); [/code] That way, until the user clicks the 'Save' button (or closes the form), the label will get updated (since the settings form is modal, it'll stop all the code after it from being run (until it's closed)) This is untested, but it should work.[/QUOTE] That did it! Thanks a ton. [editline]2nd August 2012[/editline] Do you have working undo/redo in your notepad? Mine won't work even though I copied the code from the MSDN. I've looked all around online but I can't find anything.
[QUOTE=Pelf;37056890]That did it! Thanks a ton. [editline]2nd August 2012[/editline] Do you have working undo/redo in your notepad? Mine won't work even though I copied the code from the MSDN. I've looked all around online but I can't find anything.[/QUOTE] I tried adding it - but it ceased to work after I'd create a new empty file after typing stuff, so I didn't bother altogether. Don't forget mine is in Java, so yeah :v:
[QUOTE=ConTron123;37057376]I tried adding it - but it ceased to work after I'd create a new empty file after typing stuff, so I didn't bother altogether. Don't forget mine is in Java, so yeah :v:[/QUOTE] Oh, I didn't even think to ask what language it was in. Well thanks anyway.
[QUOTE=Nigey Nige;37055581]Okay, can someone explain to me why this doesn't work? I want to be able to create a Room, then call draw() on each individual room that I create, but I Just can't get my head around what it wants from me. [code]Room = {} defaultWallTexture = love.graphics.newImage('images/wall_default.png') function Room.new(position_x, position_y, width, height) local room = {} room.pos_x = position_x room.pos_y = position_y room.size_x = width room.size_y = height --room.quad = love.graphics.newQuad(pos_x, pos_y, size_x, size_y, 2, 2) return room end function room.draw() love.graphics.rectangle('line', room.pos_x, room.pos_y, room.size_x, room.size_y) --love.graphics.drawq(defaultWallTexture, quad, pos_x, pos_y, 0, 1, 1, 0, 0, 1, 1) end[/code][/QUOTE] to make it work like you are doing it you need to define the function when you call new. Something like this: [code]Room = {} defaultWallTexture = love.graphics.newImage('images/wall_default.png') function Room.new(position_x, position_y, width, height) local room = {} room.pos_x = position_x room.pos_y = position_y room.size_x = width room.size_y = height --room.quad = love.graphics.newQuad(pos_x, pos_y, size_x, size_y, 2, 2) function room.draw() love.graphics.rectangle('line', room.pos_x, room.pos_y, room.size_x, room.size_y) --love.graphics.drawq(defaultWallTexture, quad, pos_x, pos_y, 0, 1, 1, 0, 0, 1, 1) end return room end [/code]
[QUOTE=Nigey Nige;37055581]Okay, can someone explain to me why this doesn't work? I want to be able to create a Room, then call draw() on each individual room that I create, but I Just can't get my head around what it wants from me. [code]Room = {} defaultWallTexture = love.graphics.newImage('images/wall_default.png') function Room.new(position_x, position_y, width, height) local room = {} room.pos_x = position_x room.pos_y = position_y room.size_x = width room.size_y = height --room.quad = love.graphics.newQuad(pos_x, pos_y, size_x, size_y, 2, 2) return room end function room.draw() love.graphics.rectangle('line', room.pos_x, room.pos_y, room.size_x, room.size_y) --love.graphics.drawq(defaultWallTexture, quad, pos_x, pos_y, 0, 1, 1, 0, 0, 1, 1) end[/code][/QUOTE] You can try using classes from libraries, there're lots of them. You also must include files without .lua part: [lua]--no require 'file.lua' --yes require 'file' [/lua] First doesn't work because dots are used like slashes, thus it searches for the file called "lua.lua" in directory "file"
[QUOTE=Tamschi;37055298]I want to write an Inter-Quake Export library in C# and need a valid file for testing and clarification. I have the mrfixit.iqm from the SDK, so where can I find either a compiled converter for Windows or an Inter-Quake Export file that uses as many features as possible?[/QUOTE] Here's sinbad from ogre compiled to IQM. All animations are in their own file even though one file can hold multiple animations. [url]https://dl.dropbox.com/u/99765/Sinbad_IQM.rar[/url]
[QUOTE=commander204;37058107]to make it work like you are doing it you need to define the function when you call new. Something like this: [code]Room = {} defaultWallTexture = love.graphics.newImage('images/wall_default.png') function Room.new(position_x, position_y, width, height) local room = {} room.pos_x = position_x room.pos_y = position_y room.size_x = width room.size_y = height --room.quad = love.graphics.newQuad(pos_x, pos_y, size_x, size_y, 2, 2) function room.draw() love.graphics.rectangle('line', room.pos_x, room.pos_y, room.size_x, room.size_y) --love.graphics.drawq(defaultWallTexture, quad, pos_x, pos_y, 0, 1, 1, 0, 0, 1, 1) end return room end [/code][/QUOTE] Although this would work, I suggest using metatables for class style programming in Lua. [lua]local roommeta = {} roommeta.__index = roommeta local defaultWallTexture = love.graphics.newImage('images/wall_default.png') function roommeta:Draw() love.graphics.rectangle('line', self.pos_x, self.pos_y, self.size_x, self.size_y) --love.graphics.drawq(defaultWallTexture, quad, pos_x, pos_y, 0, 1, 1, 0, 0, 1, 1) end Room = {} function Room.new(position_x, position_y, width, height) local room = {} room.pos_x = position_x room.pos_y = position_y room.size_x = width room.size_y = height --room.quad = love.graphics.newQuad(pos_x, pos_y, size_x, size_y, 2, 2) return setmetatable(room, roommeta) end[/lua]
[QUOTE=ShaunOfTheLive;37051800]To zero, you say? Tsk, tsk, tsk.[/QUOTE] Nothing wrong with that. Literal zero is a valid way to write a null pointer, and was the [i]only[/i] way prior to C++11. (NULL is just a #define that produces a zero.)
[QUOTE=MakeR;37064266]Although this would work, I suggest using metatables for class style programming in Lua. [lua]local roommeta = {} roommeta.__index = roommeta local defaultWallTexture = love.graphics.newImage('images/wall_default.png') function roommeta:Draw() love.graphics.rectangle('line', self.pos_x, self.pos_y, self.size_x, self.size_y) --love.graphics.drawq(defaultWallTexture, quad, pos_x, pos_y, 0, 1, 1, 0, 0, 1, 1) end Room = {} function Room.new(position_x, position_y, width, height) local room = {} room.pos_x = position_x room.pos_y = position_y room.size_x = width room.size_y = height --room.quad = love.graphics.newQuad(pos_x, pos_y, size_x, size_y, 2, 2) return setmetatable(room, roommeta) end[/lua][/QUOTE] Well, I decided to use the class.lua library I found for LOVE, and it seems to make sense. This is it: [code]--[[ Copyright (c) 2009 Bart Bes Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] __HAS_SECS_COMPATIBLE_CLASSES__ = true local class_mt = {} function class_mt:__index(key) return self.__baseclass[key] end class = setmetatable({ __baseclass = {} }, class_mt) function class:new(...) local c = {} c.__baseclass = self setmetatable(c, getmetatable(self)) if c.init then c:init(...) end return c end[/code] And this is what I'm doing at the moment: [code]require 'class' ship = class:new() pos_x = 0 pos_y = 0 numrooms = 0 function ship:init(position_x, position_y) self.pos_x = position_x self.pos_y = position_y self.rooms = {} self.rooms[0] = room:new(position_x, position_y, 128, 64) numrooms = 1 end function ship:addRoom(pos_x, pos_y, width, height) self.rooms[numrooms] = room:new(pos_x + numrooms, pos_y, width, height) numrooms = numrooms + 1 end function ship:draw() for i = 0, numrooms-1 do self.rooms[i]:draw() end love.graphics.print(numrooms, 0, 0) end[/code] But I'm getting 'attempt to index local 'self' (a nil value)' when I try to use the self.rooms table. That's self.rooms[i]:draw() and self.rooms[numrooms] = room:new(pos_x + numrooms, pos_y, width, height). What am I doing wrong here?
Where do you create an instance of the ship class (by calling ship:new()) and where are you calling the ship class' draw and addRoom methods?
Can classes be ignored in C++? Am I missing something about them being more essential than just a method of organizing things?
[QUOTE=MakeR;37066163]Where do you create an instance of the ship class (by calling ship:new()) and where are you calling the ship class' draw and addRoom methods?[/QUOTE] It's all in my main class, here: [code]require 'camera' require 'ntimer' require 'ship' require 'room' require 'class' function love.load() --graphics love.graphics.setDefaultImageFilter('nearest', 'nearest') love.graphics.setBackgroundColor(50, 80, 255) love.graphics.setMode(640, 480, false, true, 0) --physics love.physics.setMeter(64) space = love.physics.newWorld(0*64, 0*64, true) --zero gravity world to represent space HMSnige = ship:new() end function love.update(dt) ntimer:update() --keyboard input if love.keyboard.isDown('d') then camera.move(500 * dt, 0) end if love.keyboard.isDown("a") then camera.move(-500 * dt, 0) end if love.keyboard.isDown("w") then camera.move(0, -500 * dt) end if love.keyboard.isDown("s") then camera.move(0, 500 * dt) end if love.keyboard.isDown("e") then camera.rotate(1 * dt) end if love.keyboard.isDown("q") then camera.rotate(-1 * dt) end function love.keypressed(key) if key == "g" then HMSnige.addRoom(200,100,50,50) end end --if love.keyboard.isDown("g") then --HMSnige.addRoom(200,100,50,50) --end end function love.draw() --set camera for game drawing camera:set() --draw game HMSnige.draw() --free camera for HUD drawing camera:unset() --draw HUD end [/code]
At line 46 and line 61 you are calling a method with the wrong syntax. For the hidden argument "self" to exist you have to call the method like this: [code]HMSnige:draw() -- Same as HMSnige.draw(HMSnige) HMSnige:addRoom(200,100,50,50)[/code] [editline]3rd August 2012[/editline] Notice the ':' instead of the '.'
[QUOTE=littlefoot;37066222]Can classes be ignored in C++? Am I missing something about them being more essential than just a method of organizing things?[/QUOTE] There's no reason for you to force yourself to use something you shouldn't. But you should use classes, where classes should be used. And that isn't for everything.
[QUOTE=MakeR;37066288]At line 46 and line 61 you are calling a method with the wrong syntax. For the hidden argument "self" to exist you have to call the method like this: [code]HMSnige:draw() -- Same as HMSnige.draw(HMSnige) HMSnige:addRoom(200,100,50,50)[/code] [editline]3rd August 2012[/editline] Notice the ':' instead of the '.'[/QUOTE] Ah! Thanks. Lua's starting to make a bit more sense.
[QUOTE=T3hGamerDK;37066346]There's no reason for you to force yourself to use something you shouldn't. But you should use classes, where classes should be used. And that isn't for everything.[/QUOTE] To add on this: C++ is multi-paradigm. I write a mix of procedual and OOP when it's neccesary, because it's best not to overcomplicate things. Why have a class for stuff like 'getLocaleName()'?
[QUOTE=laylay;37063524]Here's sinbad from ogre compiled to IQM. All animations are in their own file even though one file can hold multiple animations. [url]https://dl.dropbox.com/u/99765/Sinbad_IQM.rar[/url][/QUOTE] I just finished a .iqm v2 import instead of the .iqe import I was working on originally, so this is perfect! Thanks a lot!
Trying to make a game- Nothing too fancy, probably some pixel stuff. What should I use, and what programs with it?
[QUOTE=Confuzzed Otto;37070362]Trying to make a game- Nothing too fancy, [b]probably some pixel stuff.[/b] What should I use, and what programs with it?[/QUOTE] Man, pixel stuff is the best. For srs though, if you just want to make a game go to yoyogames.com and download Game Maker. It's what Derek Yu used to make [url=http://spelunkyworld.com/original.html]Spelunky[/url]. If you really want to learn programming, then you have three options: C# with XNA Java with Slick2D Lua with Love2D But if you don't really give a shit about metatables then go with game maker.
Um sir, you forgot C++ with SFML
[QUOTE=ShaunOfTheLive;37071164]Um sir, you forgot C++ with SFML[/QUOTE] I don't think he wants C++
[QUOTE=Nigey Nige;37071530]I don't think he wants C++[/QUOTE] That doesn't mean you shouldn't include it in your list of options; C++ is the second language I learned and I think it's the best.
[QUOTE=Naelstrom;37071596]That doesn't mean you shouldn't include it in your list of options; C++ is the second language I learned and I think it's the best.[/QUOTE] stop liking what i don't like >:(
Sorry, you need to Log In to post a reply to this thread.