Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```function enemy.update(enemy)
- enemy.x = enemy.x - enemy.spd
- if enemy.x < 0 then
- enemy.x = 900
- enemy.y = math.random(25,575)
- enemy.spd = math.random(1,10)
- end
- end
- -- below is the same as enemy.update(enemy) seen above
- -- the : operator when defining a function automatically makes the first argument's name 'self'
- -- self's value is the first argument passed in
- -- myenemy.update(myenemy) passes in myenemy as the first argument
- -- myenemy:update() does the same thing
- function enemy:update()
- self.x = self.x - self.spd
- if self.x < 0 then
- self.x = 900
- self.y = math.random(25,575)
- self.spd = math.random(1,10)
- end
- end
- -- this is NOT the same as either of the two above
- -- the first argument is still called self, but you never use it
- -- instead, you used enemy
- -- the reason this is different, is because arguments are automatically local variables to the function
- function enemy:update()
- enemy.x = enemy.x - enemy.spd
- if enemy.x < 0 then
- enemy.x = 900
- enemy.y = math.random(25,575)
- enemy.spd = math.random(1,10)
- end
- end
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement