I’d just like to echo what @graham07 has said. In fact his words fit my situation so well I could have written them.
I have to say that it never ceases to amaze me the lengths that Ed goes to to answer peoples questions, and i can’t believe that it is all done ‘for the love of coding’. Ed you’re an absolute legend.
I did notice that, I had just changed it to see if it would make a difference, but now only one turret fires. Also, do you happen to know how I could edit the function turretM.fire to make it work with more than two values? (One turret, one target)
I just want the function set up so that it performs the same calculations it does now, but with all the members of a table.
I know I’m coming off angry here, but I’m just frustrated.
I want new folks to be excited about programming and game making.
I want to help them.
However, I want them to slow down and learn fundamentals first and I feel like this is partly on me.
That is, I answer questions folks ask and give working solutions, videos, complete examples, but… I think this encourages them not to question and not to puzzle things out for themselves.
I guess my real question here is, What can I do to help point folks in the right direction and to encourage the right kind of learning?
Hmmm… I see what you mean, I practically asking for the answers instead of deciding to research. you are doing a great job of helping people out in the forums, so far, as well as providing with different resources. So instead, I am going to try to brainstorm ideas myself, and I hope I can refer to you if I ever need to ask if a certain idea would work. Starting with this one:
If I placed a for loop around the function turretM.fire() code, could it work? For example:
function turretM.fire(turret, target) for a = 1, ??? do -- For all members of a table local vec = ssk.math2d.diff( turret, target ) local angle0 = ssk.math2d.vector2Angle(vec) local angle = angle0 - spread \* (projectileCount-1)/2 for i = 1, projectileCount do local vec2 = ssk.math2d.angle2Vector( angle, true ) vec2 = ssk.math2d.normalize(vec2) vec2 = ssk.math2d.scale( vec2, bulletSpeed ) local bullet = ssk.display.newImageRect( target.group, turret.x, turret.y, "arrow.png", { size = 20, rotation = angle, collision = onCollision2, myType = "bullet", fill = \_Y\_ }, { isSensor = true, radius = 10} ) bullet:toBack() bullet:setLinearVelocity( vec2.x, vec2.y ) bullet.timer = display.remove timer.performWithDelay( lifetime, bullet ) angle = angle + spread end end end
Yes, I would just like all of them to fire at one target. So, would creating a table of targets mean that there would be multiple display objects. Also, yes I would like it to loop internally.
require "ssk2.loadSSK" \_G.ssk.init( {} ) require "physics" physics.start( ) physics.setGravity(0,0) local turretM = require "turretM" local turrets = {} local background = display.newGroup() local content = display.newGroup() local function onTouch( self, event ) if( event.phase ~= "began" ) then return end local target = ssk.display.newImageRect( content, event.x, event.y, "corona256.png", { size = 40, collision = display.remove }, { radius = 20 } ) turretM.fire( turrets, target ) end ssk.display.newRect( background, centerX, centerY, { w = fullw, h = fullh, fill = \_G\_, alpha = 0.2, touch = onTouch } ) -- line of 5 turrets across the bottom of the example local ox = fullw/5 for i = 1, 5 do local turret = ssk.display.newImageRect( content, left + (i-1) \* ox + ox/2, bottom - 75, "rg256.png", { size = 100, fill = \_W\_ } ) turrets[#turrets+1] = turret end
turretM.lua
local lifetime = 5000 local projectileCount = 3 local spread = 7 local bulletSpeed = 300 local turretM = {} local function onCollision( self, event ) if( event.other.myType == "bullet" ) then return false end display.remove(self) return false end function turretM.fire( turrets, target ) for i = 1, #turrets do local turret = turrets[i] local vec = ssk.math2d.diff( turret, target ) local angle0 = ssk.math2d.vector2Angle(vec) local angle = angle0 - spread \* (projectileCount-1)/2 for j = 1, projectileCount do local vec2 = ssk.math2d.angle2Vector( angle, true ) vec2 = ssk.math2d.normalize(vec2) vec2 = ssk.math2d.scale( vec2, bulletSpeed ) local bullet = ssk.display.newImageRect( target.group, turret.x, turret.y, "arrow.png", { size = 20, rotation = angle, collision = onCollision, myType = "bullet", fill = \_Y\_ }, { isSensor = true, radius = 10} ) bullet:toBack() bullet:setLinearVelocity( vec2.x, vec2.y ) bullet.timer = display.remove timer.performWithDelay( lifetime, bullet ) angle = angle + spread end end end return turretM
@Ed, I know this topic is answered (exceedingly well I might add), but while you did convey remorse, you are actually right.
Providing complex answers to questions that is great from the perspective that the question is answered, but to your point, how much is learned.
I don’t class myself as a Corona beginner, but once I see some code such as this, I realize how much I still have to learn. This is why I like your ‘freestuff’ and full games, they are great for learning and reference.
It may be an iterative process, but I think you’re right to have the questioner work through some of it. It will allow them to learn. If they don’t, then it will lead to a 1:1 tutorial that you just can’t do for everybody. While many posters are very polite and thankful, it still means your resources are drained.
As a bad example, even as a seasoned coder I still am having trouble with tables. I have read every tutorial (both Corona and LUA), and while I get the fundamentals, I start to get lost when using same tables in different modules and indexing them. (Scope and structure). Just one of those things. However I don’t post the question as I NEED to understand the answer. I just write numerous examples until it’s clear
So, I didn’t think you were out of line, these folks are grateful for your help. You’re right to pretty much demand that people know the basics before you dedicate a lot of time to an answer.
(This is in no way any criticism of sdktester so please don’t take it as such).
_ I guess my real question here is, What can I do to help point folks in the right direction and to encourage the right kind of learning? _
Keeping code as modular as possible makes it easier for people to follow. Comments (yes I said it), will help narrow down complex points.
Kindly requesting people to search, or linking them helps too. I use search extensively to answer questions, newbies should too
A rather long 2c worth, but since you’re helping many people out, at no cost, I think you have the right to have some conditions.