A --[[comment]]-- can crash a game from loading?

Have a really dumb question? Ask it here to get help from the experts (or those with too much time on their hands)

Moderator: Moderator

Post Reply
Message
Author
xnd
Archmage
Posts: 307
Joined: Sat Mar 21, 2015 7:33 pm

A --[[comment]]-- can crash a game from loading?

#1 Post by xnd »

476 below was in a --[[comment]]--, fully greened-out txt in Notepad++, and copied fully from a game talent, even, the whole talent to test something that didnt work, so I made it a comment while trying stuff, but it still killed it.

How can a COMMENT prevent the entire game from loading? what does the --[[...]]-- do if what is inside can still kill the game? I t was totally greened out and clicking on one bracket made both red, so it was totally inside the bracket.

Yet I see mods like the xorn mod where there is code left unused inside --[[...]]--, so I thought that meant the game would ignore it like a comment. What gives here?


Lua Error: /engine/utils.lua:1782: /data-Chrono-Xorn/talents/Chrono-Xorn.lua:476: unexpected symbol near ')'
At [C]:-1
At [C]:-1 error
At /engine/utils.lua:1782 loadfilemods
At /engine/interface/ActorTalents.lua:31 loadDefinition
At /hooks/Chrono-Xorn/load.lua:10
At [string "return function(l, self, data) local ok=false..."]:1
At /mod/load.lua:271
At [C]:-1 require
At /engine/Module.lua:160 load
At /engine/Module.lua:955 instanciate
At /engine/utils.lua:2197 showMainMenu
At /engine/init.lua:162
At [C]:-1 dofile
At /loader/init.lua:204

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: A --[[comment]]-- can crash a game from loading?

#2 Post by HousePet »

Without showing us the code, you won't get a useful answer.
My feedback meter decays into coding. Give me feedback and I make mods.

Radon26
Sher'Tul
Posts: 1439
Joined: Mon Jun 23, 2014 11:50 am

Re: A --[[comment]]-- can crash a game from loading?

#3 Post by Radon26 »

you know, you could start with what --[[...]]-- is, and end with "but for better answer i need the code"

xnd
Archmage
Posts: 307
Joined: Sat Mar 21, 2015 7:33 pm

Re: A --[[comment]]-- can crash a game from loading?

#4 Post by xnd »

i had erased it, but what I have found is, take any talent that works, put --[[ ]]-- around it, and the brackets already in it will cause an error that prevents loading, for example:



--[[

newTalent{
short_name = "TELEPORT_POINT_0",
name = "Timeport: Point 0",
image = "talents/teleport_point_zero.png",
type = {"race/Chrono_Xorn", 1},
cooldown = 400,
no_npc_use = true,
no_unlearn_last = true,
no_silence=true, is_spell=true,
action = function(self, t)
if not self:canBe("worldport") or self:attr("never_move") then
game.logPlayer(self, "The spell fizzles...")
return
end

local seen = false
-- Check for visible monsters, only see LOS actors, so telepathy wont prevent it
core.fov.calc_circle(self.x, self.y, game.level.map.w, game.level.map.h, 20, function(_, x, y) return game.level.map:opaque(x, y) end, function(_, x, y)
local actor = game.level.map(x, y, game.level.map.ACTOR)
if actor and actor ~= self then
if actor.summoner and actor.summoner == self then
seen = false
else
seen = true
end
end
end, nil)
if seen then
game.log("There are creatures that could be watching you; you cannot take the risk.")
return
end

self:setEffect(self.EFF_TELEPORT_POINT_ZERO, 40, {})
self:attr("temporal_touched", 1)
self:attr("time_travel_times", 1)
return true
end,
info = [[Allows a chronomancer to timeport to Point Zero.
You have studied the chronomancy there and have been granted a special portal spell to teleport there.
Nobody must learn about this spell and so it should never be used while seen by any creatures.
The spell will take time to activate. You must be out of sight of any creature when you cast it and when the timeportation takes effect.]]
}

]]--


And what causes the error is the brackets around txt at the end:

[[Allows a chronomancer to timeport to Point Zero.
You have studied the chronomancy there and have been granted a special portal spell to teleport there.
Nobody must learn about this spell and so it should never be used while seen by any creatures.
The spell will take time to activate. You must be out of sight of any creature when you cast it and when the timeportation takes effect.]]

if I do the same thing for any talent I did this with but delete them and just -- the txt then it works.

like this talent:


info = function(self)
return
--When you kill a creature, you have a 50 percent chance to summon its clone from another timeline, one that is more likely to survive.
end,
}


if I left the brackets normally there instead of removing them, it would break the game even though its in a comment.

stinkstink
Spiderkin
Posts: 543
Joined: Sat Feb 11, 2012 1:12 am

Re: A --[[comment]]-- can crash a game from loading?

#5 Post by stinkstink »

The double brackets in the talent description are confusing it, probably. Try changing the comments to --[=[ ]=]

xnd
Archmage
Posts: 307
Joined: Sat Mar 21, 2015 7:33 pm

Re: A --[[comment]]-- can crash a game from loading?

#6 Post by xnd »

(nvm wrong paste)


i think some other stuff does it also. is there a different kind of comment brackets that will stop this bug from happening? really should not be crashing the game from code its told to ignore.

grayswandir
Uruivellas
Posts: 708
Joined: Wed Apr 30, 2008 5:55 pm

Re: A --[[comment]]-- can crash a game from loading?

#7 Post by grayswandir »

Lua doesn't parse nested comments/strings. So the --[[ comment starter ends at the ]] used to finish the info block.
Lua lets you stick = inside of them to differentiate. So a --[==[ comment will only end at a ]==], and not at the ]] used for the string.
Addons: Arcane Blade Tweaks, Fallen Race, Monk Class, Weapons Pack
Currently working on Elementals. It's a big project, so any help would be appreciated. :)

Post Reply