Simple help needed! (Spamming objects)

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.
loser123
Prole
Posts: 6
Joined: Fri Dec 29, 2017 4:55 pm

Simple help needed! (Spamming objects)

Post by loser123 »

Hello world

So, i'm kind of... TERRIBLE at programming and I can't do the code to spam objects on screen... I wanted to make some spamming projectiles to pass through the screen as shown on the image bellow but I have no idea how to make that... Can somebody (~do the whole code for me~) help me please??

Image
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Simple help needed! (Spamming objects)

Post by zorg »

Hi and welcome to the forums!

And, uh, no.

We are not your personal coding army; if you have an issue regarding your code (which you have written), and we can help with it, we will probably gladly do so, but doing all the work for someone else is probably out of the question.

But look on the bright side, nearly everyone's bad at programming when they start, that's why they learn and get better; surely you don't think all those famous devs got to where they are from getting others to do their work for them? ;)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
loser123
Prole
Posts: 6
Joined: Fri Dec 29, 2017 4:55 pm

Re: Simple help needed! (Spamming objects)

Post by loser123 »

zorg wrote: Fri Dec 29, 2017 7:42 pm Hi and welcome to the forums!

And, uh, no.

We are not your personal coding army; if you have an issue regarding your code (which you have written), and we can help with it, we will probably gladly do so, but doing all the work for someone else is probably out of the question.

But look on the bright side, nearly everyone's bad at programming when they start, that's why they learn and get better; surely you don't think all those famous devs got to where they are from getting others to do their work for them? ;)
Lol, that's fine.

Came here as last resource because I couldn't learn that by myself, wans't really expecting to someone to do everything, that was a joke.
But anyway, if I knew something that must be so simple for those who have more experience I wouldn't mind teaching that for newbies, in that way I think that the programming community really sucks.
Thanks for nothing!! :)
User avatar
Tricky
Citizen
Posts: 75
Joined: Thu Dec 18, 2014 4:07 pm
Location: Breda, the Netherlands
Contact:

Re: Simple help needed! (Spamming objects)

Post by Tricky »

I hate to say it that zork has a point that it might not be a good idea to ask us to do it for you.
When you say spam you mean multiple ones appear and they all go over the screen from down-botton to top-left?
Perhaps tables can be an idea.

Code: Select all

projectiles = {}

-- new projectile
local prj = {
   x = <x value>,
   y = <y value>
}
projectiles[#projectiles+1] = prj

-- process
for _,prj in ipairs(projectiles)
   love.graphics.draw(prjimg,prj.x,prj.y)
   prj.x = prj.x -1
   prj.y = prj.y - 1
end
Now note, I only gave you a few example lines. Copying exactly what I just said will lead you astray. I only gave some pointers how to work. Of course, now you need to UNDERSTAND what I just did in oder to work this out well. Perhaps it's a good idea to take a look at this code and try to see my approach to this.


---
There is discussion about this line "projectiles[#projectiles+1] = {}" in stead of "table.insert(projectiles,{})".
For some reason I've had a lot of errors with table.insert(), and the guys at PUC-RIO (the big guys who brought us Lua) deem the former better as it doesn't require an extra function to call on, saving some overhead, although it should in most cases not really matter.
Last edited by Tricky on Fri Dec 29, 2017 9:00 pm, edited 1 time in total.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Simple help needed! (Spamming objects)

Post by zorg »

Oh boy...



"Last Resort" you mean;

Why not? It's a simple thing to do, here: create about 50 or so projectiles outside the screen, each frame, iterating through their properities including x and y coordinates, move them along by some amount of pixels/frame (or pixels/second using dt), when one leaves the screen again, reset its position; repeat this for each and you got what you wanted.

Others having more experience doesn't negate the fact that you should learn more yourself;

It's true that some programming communities are more abrasive than others, though Löve's is one of the nicest, my first response included;
(Edit: See? someone gave you some code too! Not everyone's as jaded and salty as me. :P)

and you're welcome. :|
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
loser123
Prole
Posts: 6
Joined: Fri Dec 29, 2017 4:55 pm

Re: Simple help needed! (Spamming objects)

Post by loser123 »

Tricky wrote: Fri Dec 29, 2017 8:35 pm I hate to say it that zork has a point that it might not be a good idea to ask us to do it for you.
When you say spam you mean multiple ones appear and they all go over the screen from down-botton to top-left?
Perhaps tables can be an idea.

Code: Select all

projectiles = {}

-- new projectile
local prj = {
   x = <x value>,
   y = <y value>
}
projectiles[#projectiles+1] = {}

-- process
for _,prj in ipairs(projectiles)
   love.graphics.draw(prjimg,prj.x,prj.y)
   prj.x = prj.x -1
   prj.y = prj.y - 1
end
Now note, I only gave you a few example lines. Copying exactly what I just said will lead you astray. I only gave some pointers how to work. Of course, now you need to UNDERSTAND what I just did in oder to work this out well. Perhaps it's a good idea to take a look at this code and try to see my approach to this.


---
There is discussion about this line "projectiles[#projectiles+1] = {}" in stead of "table.insert(projectiles,{})".
For some reason I've had a lot of errors with table.insert(), and the guys at PUC-RIO (the big guys who brought us Lua) deem the former better as it doesn't require an extra function to call on, saving some overhead, although it should in most cases not really matter.

omg Thank you so much!! I was about to giving it up!
Maybe you just saved me from giving up my university too lol
loser123
Prole
Posts: 6
Joined: Fri Dec 29, 2017 4:55 pm

Re: Simple help needed! (Spamming objects)

Post by loser123 »

zorg wrote: Fri Dec 29, 2017 8:37 pm Oh boy...



"Last Resort" you mean;

Why not? It's a simple thing to do, here: create about 50 or so projectiles outside the screen, each frame, iterating through their properities including x and y coordinates, move them along by some amount of pixels/frame (or pixels/second using dt), when one leaves the screen again, reset its position; repeat this for each and you got what you wanted.

Others having more experience doesn't negate the fact that you should learn more yourself;

It's true that some programming communities are more abrasive than others, though Löve's is one of the nicest, my first response included;
(Edit: See? someone gave you some code too! Not everyone's as jaded and salty as me. :P)

and you're welcome. :|
Well well, as for you, wish you to be less... Selfish
Helping others is a good thing for you to grow as a person, it is ok not wanting to help sometimes, but you should try making other's day better instead of you know... doing what you do!
I'm not replying further so don't worry writing something about how this is not a "lovely best friends forum" or whatever but I wish you the best anyway, bye bye
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Simple help needed! (Spamming objects)

Post by zorg »

loser123 wrote: Fri Dec 29, 2017 8:52 pmWell well, as for you, wish you to be less... Selfish
Helping others is a good thing for you to grow as a person, it is ok not wanting to help sometimes, but you should try making other's day better instead of you know... doing what you do!
I'm not replying further so don't worry writing something about how this is not a "lovely best friends forum" or whatever but I wish you the best anyway, bye bye
Top
Interpret what i wrote as you wish, i do have the freedom to share my opinions though, as do you.

Me not giving you code after your first post basically demanding an instant-solution is not me being selfish, rather me being overly straight to the point regarding what you will accomplish in the future, with just a touch of attitude; granted, by how you conducted yourself, i did assume you weren't even going to try, your message demonstrating a lack of willingness on your part; in my reading anyway. (And i did write out the basic steps you should have done to achieve what you wanted)

Also, i'm not here to stroke anyone's ego; again, had you shown a bit more will to at least try, i probably would have been nicer.
It's fine if you don't reply, i clearly struck a nerve; that said, i do hope i'm wrong and you will become gradually better at coding, so i wish you the same.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Tricky
Citizen
Posts: 75
Joined: Thu Dec 18, 2014 4:07 pm
Location: Breda, the Netherlands
Contact:

Re: Simple help needed! (Spamming objects)

Post by Tricky »

Hehehe... I began coding like this:

Code: Select all

10 PRINT "What is your name?"
20 INPUT NAME$
30 PRINT "Hello "; NAME$;"; nice to meet you!"
40 END
And all I had was characters... Ah, those were the days. It made my own start easier, although I had no internet back then (nobody did), so I went in a bit the "hard way". Just trying stuff out, seeing what would happen. It's a hard way to learn, but I guess I could never come where I am now when I didn't try so much back then ;)

Oh yeah, and I know about rude programming communities. Like the Lazarus community where I was told to "learn to code" due to a error in the code written by the Lazarus programmers themselves (and thus not me). Now you can call me a dummy, but I wonder how I am to blame for a code error in Lazarus' own code (the error was "Unknown identifier"). I guess I won't be using Lazarus for my GUI based programs :P
(All I did was open a template project and try to compile it. Wow, what a lousy programmer I am) :P

I did find a little mistake in my example code and I fixed that. Sorry, I shouldn't cause confusion.

Mastering the use of tables is a very important aspect of Lua. When trying the "real" languages like C or Pascal you'll have more complex things to deal with, but when you analyse that code well you can see the same principal as the tables in Lua, only in Lua it's heavily simplefied. (Question always is what a "real language" is. I still meet some people who only deem pure assembler code as programming. I guess it depends on who you ask).

Just a few nice thing to know about tables

Code: Select all

a = {} -- create new table. Variable a is the table.
a[#a+1] = "Hello" -- #a is the number of indexes. That's now 0, so 0+1 = 1 so a[1]="Hello" now.
print ( a[1] ) -- prints "Hello"
a[2] = {} -- extra table on a[2]
a[2][1] = "Hi"
print (a[2][1]) -- "Hi"
print (a[1]) -- "Hello"
I shall keep it to this now, as tables can do so much more in Lua. They can basically help you getting you thing solved.

The for command was in this case use to list out all contents of the table with the help of ipairs.
Now try to analyse this and try some stuff out ;)

Also Google is your friend. A lot of questions about the Lua language are answered already by googling it. A lot of solutions for you needs may often not lie in LOVE itself, but rather in Lua itself. Since Lua is used as a scripting language for many things, Lua help pages can deal with quite a lot of stuff. (And bookmark stackoverflow.com -- In 90% of the cases when I have any question about any programming language (aside from Lua I also work in BlitzMax, php, Python, Pascal and Go) somebody else already asked it there before and answers are mostly already provided :)
loser123
Prole
Posts: 6
Joined: Fri Dec 29, 2017 4:55 pm

Re: Simple help needed! (Spamming objects)

Post by loser123 »

Thanks again Tricky!" I'll do my best
Post Reply

Who is online

Users browsing this forum: Roland Chastain and 236 guests