[Error] Starfall: Custom nocollideall method throwing an assertion error
7 replies, posted
I've been trying to add a simple nocollideall method to Starfall's entity methods. Sounded easy enough to me, but when I called the method in a chip it threw "addons/starfall/lua/starfall/sflib.lua:202: assertion failed!"
The method in question:
[lua]
--- Sets the nocollideall property of the entity
function ents_methods:setCollision ( bool )
if not SF.Permissions.check( SF.instance.player, ent, "entities.setCollision" ) then SF.throw( "Insufficient permissions", 2 ) end
SF.CheckType( self, ents_methods )
local ent = unwrap ( self )
if IsValid( ent ) and bool then
ent:SetCollisionGroup( COLLISION_GROUP_NONE )
elseif IsValid( ent ) and not bool then
ent:SetCollisionGroup( COLLISION_GROUP_WORLD )
end
end
[/lua]
If you need more resources (code lines, what the line does, entire .lua files, etc) to work this out then let me know.
[B]Keep in mind that I am a novice GLua scripter. This may or may not be a really stupid question with a really simple solution.[/B]
Bump!
Dont bump after 5 hours. Not many here use starfall and if someone knows how to fix it, he will probably tell you
Yeah, the hasty bump wasn't needed. I'll admit that. On the other hand, this post is about Starfall's Lua code instead of Starfall itself (which is still Lua anyway). I figured if I could get help anywhere it'd be here.
Post the full trace stack, that way we can see which function called sflib to error.
[code]
addons/starfall/lua/starfall/sflib.lua:202: assertion failed!
stack traceback:
[C]: in function 'assert'
addons/starfall/lua/starfall/sflib.lua:202: in function 'CheckType'
addons/starfall/lua/starfall/libs_sv/entities.lua:403: in function 'setCollision'
SF:main:8: in function 'func'
addons/starfall/lua/starfall/instance.lua:81: in function <addons/starfall/lua/starfall/instance.lua:80>
[C]: in function 'xpcall'
addons/starfall/lua/starfall/instance.lua:89: in function 'runWithOps'
addons/starfall/lua/starfall/instance.lua:148: in function 'initialize'
addons/starfall/lua/entities/starfall_processor/init.lua:32: in function 'Compile'
addons/starfall/lua/weapons/gmod_tool/stools/starfall_processor.lua:35: in function 'callback'
addons/starfall/lua/starfall/sflib.lua:539: in function 'func'
lua/includes/extensions/net.lua:32: in function <lua/includes/extensions/net.lua:17>
[/code]
There ya go.
So, as I suspected, it seems that
[code]SF.CheckType( self, ents_methods )[/code]
Is the one causing the error.
"self" in this context is a reference to "ents_methods" as a : was used in the function name, being that self is automatically passed as an argument, however, you then also pass ents_methods once again.
I don't know much if anything about Starfall but it seems that you're misusing the function SF.CheckType
[B]Edit:[/B]
I went on github and found some uses:
[B]SF[/B].[B]CheckType[/B]( path, "string" )
[B]SF[/B].[B]CheckType[/B]( flags, "string" )
[B]SF[/B].[B]CheckType[/B]( callback, "function" )
Seems like the first argument is meant to be a variable to check, and the second argument would be the type.
So essentially what you're doing is:
if ( self == type( ents_methods ) ) ...
-snip-
[editline]21st March 2016[/editline]
Ugh, I feel stupid. I was editing my vanilla copy of Starfall. Durr.
[editline]21st March 2016[/editline]
Ok, so yes, SF.CheckType is throwing an error, and you were correct about its purpose. I also found that I made two mistakes:
a. Script was not running in in sv, which seemed to be a problem - probably because of ent:SetCollisionGroup
b. I was using ents_methods instead of ents_metatable, which most of the other functions seem to use when checking the type of the variable that the method's being run on. I'm guessing "ents_methods", "ents_metatable", "ents_metamethods", etc. are enumerations, and in that case it'd probably be useful to learn what they actually are.
Here's the new code.
[lua]
--- Sets the nocollideall property of the entity
function ents_methods:setCollision ( bool )
if not SF.Permissions.check( SF.instance.player, ent, "entities.setCollision" ) then return end
SF.CheckType( self, ents_metatable )
local ent = unwrap ( self )
if IsValid( ent ) and bool then
ent:SetCollisionGroup(0)
elseif IsValid( ent ) and not bool then
ent:SetCollisionGroup(20)
end
end
[/lua]
Works fine. Thanks for the help.
Sorry, you need to Log In to post a reply to this thread.