[SOLVED] Label.set_text not setting the label value

local ATTRIBUTES = { 
	isbn = "",
	content = nil
}

local function create_isbn()
	local charset = {} do
		-- Ký tự [0-9a-zA-Z] dưới dạng  mã ASCII: https://www.rapidtables.com/code/text/ascii-table.html
		for c = 48, 57  do table.insert(charset, string.char(c)) end
		for c = 65, 90  do table.insert(charset, string.char(c)) end
		for c = 97, 122 do table.insert(charset, string.char(c)) end
	end
	ATTRIBUTES.isbn =  charset[math.random(1, #charset)] .. charset[math.random(1, #charset)]  .. charset[math.random(1, #charset)]  .. charset[math.random(1, #charset)]  .."-" .. charset[math.random(1, #charset)] .. charset[math.random(1, #charset)] .. charset[math.random(1, #charset)] .. charset[math.random(1, #charset)]  .."-" .. charset[math.random(1, #charset)] .. charset[math.random(1, #charset)] .. charset[math.random(1, #charset)] .. charset[math.random(1, #charset)]  .."-" .. charset[math.random(1, #charset)] .. charset[math.random(1, #charset)] .. charset[math.random(1, #charset)] .. charset[math.random(1, #charset)]
end

Hello, I’ve been debugging and am confused as to why isbn can’t be updated to its new value? Shouldn’t the script be able to access the table’s property considering the table is part of it? Thanks to anyone who answers.

Yes, it should. How are you calling create_isbn()?

Through another script that then passes a message to the book.

local function create_book()
	delete_book()

	book_inst= factory.create("#book",  vmath.vector3(0, 540, 0), vmath.quat(0, 0, 0, 1), nil, 2)
	msg.post(book_inst, "set_isbn")
	msg.post(book_inst, "book_sliding_sfx")
end

function init(self)
	msg.post(".", "acquire_input_focus")
	create_book()
end

And in the on_messagefunction of the book script:

function on_message(self, message_id, message, sender)
	if message_id == hash("set_isbn") then
		create_isbn()
	end
	
	if message_id == hash("book_sliding_sfx") then
		play_book_sliding_sound()
	end
end

:thinking: Another question I have is thatt if I’m passing an instance into msg.post, like in this case, whatever functions I call and variable values I modify, would it only apply to this specific instance? Because I know self is like a table that stores modified values for that specific instance, but either way I’ll always be respawning one instance at a time so there’ll never be more than one.

Yes, Lua tables sent using msg.post() are copied.

1 Like

:man_facepalming: I know the issue, my z value for the position of the label was too far forward. I am so sorry.

1 Like