HOLY CRAP, I FEEL DUMB. Also I was having dinner and that popped into my head, I was thinking about how I had arguments inside of insert-book-code.script
and they all passed self
. THAT MAKES SENSE NOW.
Wait though, would I even need to make the variables inside of book.script
unique? Considering I’m using the factory to make a unique instance each time?
Thanks by the way for sticking it out with me.
Ok, I’m making progress though, managed to fix another error, it was the msg.post
one, I was passing a string instead of a table and it didn’t like that, and I fixed it, still got a few errors to go though.
It’s spawning a book at least.
ERROR:GAMEOBJECT: Component '/instance0#random_book_code_label' could not be found when dispatching message 'set_text' sent from default:/instance0#random-book
ERROR:GAMEOBJECT: Instance '<unknown>' could not be found when dispatching message 'play_sound' sent from default:/minigame_go#insert-book-code
INFO:DLIB: SSDP: Started on address 10.0.0.78
ERROR:SCRIPT: ...games/inventory/insert-book-code/insert-book-code.script:25: Could not send message 'game_over' from 'default:/minigame_go#insert-book-code' to 'main:/main'.
stack traceback:
[C]:-1: in function post
...games/inventory/insert-book-code/insert-book-code.script:25: in function <...games/inventory/insert-book-code/insert-book-code.script:24>
Ah ok, I’d probably have to pass in that instance for the url then.
local function generate_book_code(self)
self.book_code = ""
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
-- [0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}
while (string.len(self.book_code) <= 19) do
if (#self.book_code % 5 == 0) then
self.book_code = self.book_code .."-"
else
self.book_code = self.book_code .. charset[math.random(1, #charset)]
end
end
-- Ok, this is the issue here. I already tried to pass self"#random_book_code_label" but that didn't work
label.set_text("#random_book_code_label", self.book_code)
msg.post("/computer#computer", "actual_book_code", {book_code = self.book_code})
end
Wait nope, fixed that issue too, turns out I got the wrong name for the label. There’s still the play_sound
issue, will try to figure that out, in fact I’m trying to find where it is. Got the sound to work. Gotta figure out how to make my spawned game object bigger, I’ll figure that out, I think you can specify scale with factory. Unless there’s a way to do that in the game object itself. Another one is to figure out how to check to see if your typed input matches the book code, hm. Oh yea, and trying to figure out how to return to the main collection and then loading the next minigame. We’ll get to that when we get to that.