Started My Very First Love2d Game

Show off your games, demos and other (playable) creations.
User avatar
kingnoob
Prole
Posts: 29
Joined: Thu Dec 21, 2023 6:52 am

Re: Started My Very First Love2d Game

Post by kingnoob »

Bobble68 wrote: Wed Dec 27, 2023 9:01 pm Something seems to be up with the way you've packaged your game - normally if you have Love2D installed, you should be able to run the .love file directly. I could only do that once I unzipped it and repackaged it myself.

What method are you using for this?

Other than that, seems to be coming along nicely! My other piece of feedback is that you seem to be using a good deal of global variables, rather than local ones. I'm not one of those people who thinks globals should be illegal, but I will say they should be used sparingly - locals are a little faster, and are less likely to cause you issues down the line. If you have an issue that affects one of your globals, it will be much more difficult to track it down, especially if it's the result of a typo.
I changed the name of the folder to VerySimpleSpaceGame that is probably the reason for the run problem. I make a variable global if it is used in more than one function. What I guess I'm forgetting to do because I'm new to Lua is to use the local keyword everywhere I should. I'll need to spiff it up a bit. It does have a nice feel to it and I think I'm doing a decent job organizing the code and keeping it clean and simple. Thanks
User avatar
kingnoob
Prole
Posts: 29
Joined: Thu Dec 21, 2023 6:52 am

Re: Started My Very First Love2d Game

Post by kingnoob »

Another long day and some nice progress. All that remains to be done now to have a pre alpha but playable game is to write the computer players AI. As it is now the human player can send ships to planets in range and conquer the galaxy with no opposition. Napoleon, Hitler and P___n sure could of used someone like me. lol Sorry, poor joke. Anyway just click on the/a medium blue star and then on any other mb star or enemy that is in range and send some ships. The send ships panel is not complete yet so please give me a pass on that. Remember, escape exits and n starts a new 'game'. Well not quite a game yet but getting there! :)
Attachments
VerySimpleSpaceGame.love
(5.68 KiB) Downloaded 40 times
User avatar
dusoft
Party member
Posts: 510
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Started My Very First Love2d Game

Post by dusoft »

Probably incorrectly packaged:

Code: Select all

Error

[love "boot.lua"]:321: No code to run
Your game might be packaged incorrectly.
Make sure main.lua is at the top level of the zip.


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'error'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
User avatar
kingnoob
Prole
Posts: 29
Joined: Thu Dec 21, 2023 6:52 am

Re: Started My Very First Love2d Game

Post by kingnoob »

dusoft wrote: Thu Dec 28, 2023 11:04 am Probably incorrectly packaged:

Code: Select all

Error

[love "boot.lua"]:321: No code to run
Your game might be packaged incorrectly.
Make sure main.lua is at the top level of the zip.


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'error'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
I use 7-Zip to zip folder VerySimpleSpaceGame. In that folder are all the source files:
colors.lua
draw.lua
globals.lua
initiate.lua
main.lua
update.lua
utils.lua

That produces file VerySimpleSpaceGame.zip

I change the .zip to .love as instructed and attach it.

So what am I doing wrong?

So maybe I should just zip the files and not the folder? I'll try that. Okay done.

Thanks
Attachments
VerySimpleSpaceGame.love
No folder this time
(5.26 KiB) Downloaded 38 times
User avatar
Bobble68
Party member
Posts: 160
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Started My Very First Love2d Game

Post by Bobble68 »

kingnoob wrote: Wed Dec 27, 2023 10:37 pm
I make a variable global if it is used in more than one function. What I guess I'm forgetting to do because I'm new to Lua is to use the local keyword everywhere I should. I'll need to spiff it up a bit. It does have a nice feel to it and I think I'm doing a decent job organizing the code and keeping it clean and simple. Thanks
There are always alternatives to using globals - one I would recommend is using requires to replace them (I've only just begun using this method myself, I wish I had been using it earlier).

Local variables within the same module can be accessed by multiple functions, for example:

Code: Select all

--donuts.lua
local donuts = 1000

function getDonuts()
  return donuts
end

function eatDonuts()
  donuts = 0
end


--main.lua
require("donuts")

print(getDonuts())
eatDonuts()
print(getDonuts())
This way, you can't accidentally change the number of donuts from other modules, as well as accessing it being slightly faster (the functions here are still global there, so they don't get that benefit).

So the require method I mentioned before works like this - the require function can return values from the target module. Since tables are passed by reference, this means you can essentially create global variables where you can control the scope (scope is the term for where variables are and aren't valid).

Code: Select all

--colours.lua

local colour = {}

colour.red =   {1, 0, 0}
colour.green = {0, 1, 0}
colour.blue =  {0, 0, 1}

return colour

--main.lua

local colour = require("colours")

love.graphics.setBackgroundColor(colour.green)
This example isn't all that useful, and afaik it's not faster than using globals (globals are actually just table lookups, you can access the table with _G), however in some cases this can be useful so you can control where colours can be accessed, or even rename the variable if you want. I would still recommend using globals however if said value is needed in a lot of your modules (for instance, a table with settings for the game).

Sorry that was a bit of a lecture, just use what works for you, though its best to keep these things in mind.

kingnoob wrote: Thu Dec 28, 2023 12:57 pm So maybe I should just zip the files and not the folder? I'll try that. Okay done.

Thanks
That seems to have fixed it! Love will look for main at the bottom level, so an extra folder was confusing it.
Dragon
User avatar
dusoft
Party member
Posts: 510
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Started My Very First Love2d Game

Post by dusoft »

kingnoob wrote: Thu Dec 28, 2023 12:57 pm So maybe I should just zip the files and not the folder? I'll try that. Okay done.

Thanks
Very simple space game indeed. It took me a minute to understand what a player should be doing. Dragging a line would help in addition to clicks. Also it's not clear what the starting planet is and also why in range says "NA" (once one identifies their home planet, it's alright).

Well done. I like the planet names.
User avatar
kingnoob
Prole
Posts: 29
Joined: Thu Dec 21, 2023 6:52 am

Re: Started My Very First Love2d Game

Post by kingnoob »

dusoft wrote: Thu Dec 28, 2023 3:42 pm
kingnoob wrote: Thu Dec 28, 2023 12:57 pm So maybe I should just zip the files and not the folder? I'll try that. Okay done.

Thanks
Very simple space game indeed. It took me a minute to understand what a player should be doing. Dragging a line would help in addition to clicks. Also it's not clear what the starting planet is and also why in range says "NA" (once one identifies their home planet, it's alright).

Well done. I like the planet names.
Thanks!

NA means Not Applicable because one's own stars are always in range (slipstream projectors at both stars, lol). this though is temporary until more functionality is added.

Dragging a line is just a way of showing that selection is in progress. But I should have mentioned that. Soon I'll make a readme that can be updated as progress is made. The game (it is a game now) starts off paused. While not in selection mode paused is toggled by clicking the right mouse button on empty space. Sometimes it is just too hectic not to pause the game. And orders can be entered while paused. I'll make a follow up post shortly about the changes. Maybe blinking the human's home planet while paused will help it to be found. It is not easy coming up with 200 star names. Some of them I made up out of thin air,lol.
User avatar
kingnoob
Prole
Posts: 29
Joined: Thu Dec 21, 2023 6:52 am

Re: Started My Very First Love2d Game

Post by kingnoob »

Bobble68 wrote: Thu Dec 28, 2023 1:37 pm There are always alternatives to using globals - one I would recommend is using requires to replace them
I will study this and spiff up the code when I understand it better. Though most of the globals are used in more than one module/file. I just need to study it for awhile. Thanks
User avatar
dusoft
Party member
Posts: 510
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Started My Very First Love2d Game

Post by dusoft »

kingnoob wrote: Thu Dec 28, 2023 5:38 pm Dragging a line is just a way of showing that selection is in progress. But I should have mentioned that. Soon I'll make a readme that can be updated as progress is made.
I meant having an option to drag a line from one planet to another as an alternative to clicking first and clicking second. I tried that, but it didn't work and it took me a second to find out I can click on a planet and then another and that initiates transfer.
User avatar
kingnoob
Prole
Posts: 29
Joined: Thu Dec 21, 2023 6:52 am

Re: Started My Very First Love2d Game

Post by kingnoob »

Houston we have liftoff! It is a real game now!! :awesome: It is still pre alpha or maybe even pre pre alpha but it is playable.

The AI is the simplest (and stupidest) AI I can make that is just above random. It can and will give one grief at times.

The game starts off paused. Toggle paused by right clicking on open space while not in any gui mode.

I can't play very long because my aio cpu cooler is on the fritz and the cpu is getting hot while running the game. So it seems okay but I haven't tested it like it should be tested. This is probably a good time to add a save file.

The biggest change to sending ships is ships can be sent to any enemy star that is in range of any of the players other stars. Well it is a game rather than a simulation so i'll be taking many liberties with reality to keep the game simple.

Remember, escape exits and n starts a new game. I just realized the fleets are not cleared on pressing n so that might be a problem. Starting a new game while initially paused would be okay if one does not like their starting position.

readme coming soon. Even very simple space games require a lot of work. I hope someone likes my game. :)
Attachments
VerySimpleSpaceGame.love
(5.77 KiB) Downloaded 66 times
Post Reply

Who is online

Users browsing this forum: No registered users and 55 guests