Hello people!
I have been writing a very basic roguelike game for one of my friends
When i decided to abstract the characters to an actor class, all sorts of weird things began to happen
1) It refused to accept a function call to sprites created in an actor table
2) It refused to perform arithmetic on delta time passed into the actor class, saying it was a table value.
The sprite error causing lines have been commented out of actors.lua
I would like it if you would offer me a solution to both the problems.
Thank you in advance.
[SOLVED]Errors attempting to do acess tables
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Errors attempting to do acess tables
One of the main problems is that you're assigning to globals
That means, that when you call jk:load(), after calling newSprite, t no longer refers to the same object as jk, so things get really weird.
If you replace t = {} by local t = {} in both actor.lua and sprite.lua, it'll get you a long way. You'll still have some other issues to deal with, though. Mainly about things like scope, and the difference between a.b() and a:b().
That means, that when you call jk:load(), after calling newSprite, t no longer refers to the same object as jk, so things get really weird.
If you replace t = {} by local t = {} in both actor.lua and sprite.lua, it'll get you a long way. You'll still have some other issues to deal with, though. Mainly about things like scope, and the difference between a.b() and a:b().
Help us help you: attach a .love.
Re: Errors attempting to do acess tables
Thanks. What's the difference between a.b() and a:b() may i ask?
EDIT: After applying your fix, i get this:
What's gone wrong now?
EDIT: After applying your fix, i get this:
Code: Select all
Error: anim8.lua:229: attempt to perform arithmetic on local 'dt' (a table value)
stack traceback:
anim8.lua:229: in function 'update'
sprites.lua:33: in function 'update'
actors.lua:15: in function 'update'
main.lua:15: in function 'update'
[string "boot.lua"]:434: in function <[string "boot.lua"]:399>
[C]: in function 'xpcall'
- Attachments
-
- jk-new.love
- (9.36 KiB) Downloaded 106 times
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Errors attempting to do acess tables
a:b() is syntactic sugar.
For function definitions, something like:
is the same as
and for function calls, world:destroy() is the same as world.destroy(world) (except world is only evaluated once).
So if you do
my expectation would be that the definition would be something like this:
That way it wouldn't have mattered the global variable t was overwritten.
For function definitions, something like:
Code: Select all
function screen:load()
--
end
Code: Select all
function screen.load(self)
--
end
So if you do
Code: Select all
jk = newActor("Justforkix.png", 5, 5)
jk:load()
Code: Select all
function t:load()
self.sprite = {}
self.sprite = newSprite(spriteFile)
self.x = x
self.y = y
self.direction = "Down"
self.speed = 150
end
Help us help you: attach a .love.
Re: Errors attempting to do acess tables
Thanks! The problem is now solved.
Here is the final .love where you can enjoy watchng him walk around the screen
Here is the final .love where you can enjoy watchng him walk around the screen
- Attachments
-
- jk-final.love
- (9.36 KiB) Downloaded 122 times
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests