Note that there are some explanatory texts on larger screens.

plurals
  1. POXmlParser in Gideros with Lua
    primarykey
    data
    text
    <p>I'm working with Gideros and I got the error but I don't know why and how to fix. The error is: </p> <blockquote> <p>attempt to index local 'xml_layout_x'</p> </blockquote> <p>My build: <a href="http://www.mediafire.com/download/utowfooin439b66/Ex2.zip" rel="nofollow">http://www.mediafire.com/download/utowfooin439b66/Ex2.zip</a></p> <p>This is my header.xml</p> <pre><code>&lt;rss version="2.0"&gt; &lt;layout&gt; &lt;layout_x&gt;35&lt;/layout_x&gt; &lt;layout_y&gt;150&lt;/layout_y&gt; &lt;layout_width&gt;825&lt;/layout_width&gt; &lt;image&gt; &lt;width&gt;270&lt;/width&gt; &lt;height&gt;240&lt;/height&gt; &lt;/image&gt; &lt;table&gt; &lt;layout_x&gt;25&lt;/layout_x&gt; &lt;tablerow textview_name=".Name:" edittext_name_height="18" edittext_name_width="245" edittext_name_offset_x="150" textview_born=".Born:" textview_weight=".Weight:" textview_bio=".Bio:" edittext_bio_width="441" edittext_bio_height="71" /&gt; &lt;/table&gt; &lt;action&gt; &lt;name&gt;update&lt;/name&gt; &lt;/action&gt; &lt;file:path bio="bio_001.txt" image="Avatar_001.png"/&gt; &lt;file:path bio="bio_002.txt" image="Avatar_002.png"/&gt; &lt;/layout&gt; &lt;/rss&gt; </code></pre> <p>Then, it's my code</p> <pre><code>local function getChild(xml, name) for i=1,#xml.ChildNodes do if xml.ChildNodes[i].Name == name then return xml.ChildNodes[i] end end end -- helper function to get all children of xml node by name local function getChildren(xml, name) local result = {} for i=1,#xml.ChildNodes do if xml.ChildNodes[i].Name == name then result[#result + 1] = xml.ChildNodes[i] end end return result end info = gideros.class(Sprite) if info.innerSprite ~= nil then info:removeChild(self.innerSprite) end info.innerSprite = Sprite.new() info.innerSprite:setPosition(200, 10) local font = TTFont.new("Roboto-Regular.ttf", 38) local small_font = TTFont.new("Roboto-Regular.ttf", 30) function info:init() local xml = XmlParser:ParseXmlFile("header.xml") local layout = getChild(xml, "layout") local filepath = getChildren(layout, "file:path") local logo = Bitmap.new(Texture.new("logo.png")) self:addChild(logo) logo:setPosition(780, 5) local Update_Btn = Bitmap.new(Texture.new("Update_Btn.png")) self:addChild(Update_Btn) Update_Btn:setPosition(33, 23) Update_Btn:addEventListener(Event.MOUSE_DOWN, function() -- Get source local src_bio = {} local src_image = {} for i = 1, #filepath do table.insert(src_bio, filepath[i].Attributes["bio"]) table.insert(src_image, filepath[i].Attributes["image"]) end -- Check if file exist for i = 1, #filepath do local bio_file = io.open(src_bio[i]) local image_file = io.open(src_image[i]) if (bio_file == nil or image_file == nil) then table.remove(src_bio, i) table.remove(src_image, i) else bio_file:close() image_file:close() end end -- Get content local tbInfo_List = {} for i = 1, #src_bio do tbInfo_List[i] = {} local tbInfo_tmp1 = ReadFile(src_bio[i]) local tbInfo_tmp2 = ConvertTable(tbInfo_tmp1) table.insert(tbInfo_List[i], tbInfo_tmp2) end -- Fill content local xml_layout_x = getChild(layout, "layout_x") *=&gt; the error is HERE* local layout_x = xml_layout_x.Value local xml_layout_y = getChild(layout, "layout_y") local layout_y = xml_layout_y.Value local xml_layout_width = getChild(layout, "layout_width") local layout_width = xml_layout_width.Value for i = 1, #tbInfo_List do local tmp_y = layout_y + layout_width*(i - 1) + 25 table.insert(tbInfo_List[i], src_image[i]) CreateInformationTag(layout_x, tmp_y, tbInfo_List[i], layout) end end ) local Exit_Btn = Bitmap.new(Texture.new("Exit_Btn.png")) self:addChild(Exit_Btn) Exit_Btn:setPosition(397, 23) Exit_Btn:addEventListener(Event.MOUSE_DOWN, function() sceneManager:changeScene("home", 1, transition, easing.outBack) end ) end local function CreateInformationTag(x,y, tbInfo, layout) local image = Bitmap.new(Texture.new(tbInfo.image)) local name = tbInfo.name local born = tbInfo.born local weight = tbInfo.weight local bio = tbInfo.bio --Add Image image.setPosition(x, y) self.innerSprite.addChild(image) local xml_image = getChild(layout, "image") local xml_image_width = getChild(layout, "width") local image_width = xml_image_width.Value() local xml_table = getChild(layout, "table") local xml_table_layout_x = getChild(xml_table, "layout_x") local table_layout_x = xml_table_layout_x.Value() local xml_table_row = getChild(xml_table, "tablerow") local tbTextView = {} -- .Name local xml_table_row_textview_name = getChild(xml_table_row, "textview_name") table.insert(tbTextView, xml_table_row_textview_name.Value()) -- .Born local xml_table_row_textview_born = getChild(xml_table_row, "textview_born") table.insert(tbTextView, xml_table_row_textview_born.Value()) -- .Weight local xml_table_row_textview_weight = getChild(xml_table_row, "textview_weight") table.insert(tbTextView, xml_table_row_textview_weight.Value()) -- .Bio local xml_table_row_textview_bio = getChild(xml_table_row, "textview_bio") table.insert(tbTextView, xml_table_row_textview_bio.Value()) local table_x = x + image_width + table_layout_x local table_y = y local table_offset_y = 20 -- Add label for i = 1, 4 do local textfield = TextField.new(font, tbTextView[i]) local tmp_y = table_y + (i - 1)*table_offset_y textfield:setPosition(table_x, tmp_y) self.innerSprite:addChild(textfield) end -- Add text box local edittext_name_offset_x = getChild(xml_table_row, "edittext_name_offset_x") local name_offset_x = edittext_name_offset_x.Value() local edittext_name_width = getChild(xml_table_row, "edittext_name_width") local name_width = edittext_name_width.Value() local edittext_name_height = getChild(xml_table_row, "edittext_name_height") local name_height = edittext_name_height.Value() -- Draw text box for i = 1, 3 do local line = Shape.new() local tmp_y = table_y + table_offset_y*(i - 1) line:setLineStyle(5, 0x000000, 1) line:beginPath() line:moveTo(table_x + edittext_name_x,tmp_y) line:lineTo(table_x + edittext_name_x + name_width, tmp_y) line:lineTo(table_x + edittext_name_x + name_width, tmp_y + name_height) line:lineTo(table_x + edittext_name_x, tmp_y + name_height) line:lineTo(table_x + edittext_name_x, tmp_y) line:endPath() self.innerSprite:addChild(line) end -- Draw bio text box local edittext_bio_width = getChild(xml_table_row, "edittext_bio_width") local bio_width = edittext_bio_width.Value() local edittext_bio_height = getChild(xml_table_row, "edittext_bio_height") local bio_height = edittext_bio_height.Value() local line_bio = Shape.new() line_bio:setLineStyle(5, 0x000000, 1) line_bio:beginPath() line_bio:moveTo(table_x + edittext_name_x,tmp_y) line_bio:lineTo(table_x + edittext_name_x + bio_width, tmp_y) line_bio:lineTo(table_x + edittext_name_x + bio_width, tmp_y + bio_height) line_bio:lineTo(table_x + edittext_name_x, tmp_y + bio_height) line_bio:lineTo(table_x + edittext_name_x, tmp_y) line_bio:endPath() self.innerSprite:addChild(line_bio) -- Add text in box for i = 1, 3 do local textfield = TextField.new(small_font, tbInfo[i]) local tmp_y = table_y + (i - 1)*table_offset_y textfield:setPosition(table_x, tmp_y) self.innerSprite:addChild(textfield) end -- Add wrap text local tw = TextWrap2.new(tbInfo[4], table_x, table_y + 2*table_offset_y , 18, small_font) self.innerSprite:addChild(tw) end function ReadFile(filename) local tbInfo = {} fp = io.open(filename, "r") for line in fp:lines() do table.insert(tbInfo, line) end fp:close() return tbInfo end function ConvertTable(tbInfo) local tmp = {} for i = 1, #tbInfo do if (i &lt;= 4) then&lt;br /&gt; table.insert(tmp, tbInfo[i]) else local str1 = tmp[5] local str2 = tbInfo[i] table.remove(tmp, 5) local str = str1 + str2 table.insert(tmp, str) end end return tmp end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload