Help with Lua

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Rhinoceros
Prole
Posts: 35
Joined: Mon Jun 11, 2012 2:59 am
Location: Under the Floorboards

Help with Lua

Post by Rhinoceros »

Alright, so I have this Code block,

Code: Select all

stop = 0
repeat
qset1 = {
	tl1 = "This is a line of text, also known as a atring.",
	tl2 = "Strings are static variables that I dont' konw ho w to edit yet.",
	tl3 = "poopy poo poop. Type \"a\", \"b\", \"c\", or \"d\".",
	qa = "You chose a",
	qb = "u choez b",
	qc = "Cose c.",
	qd = "these words don't matter.",
	anext = qset2,
	bnext = qset3,
	cnext = qset4,
	dnext = qset5,}
qset2 = {
	tl1 = "This is the second question set",
	tl2 = "Testing the third line not being printed:",
	tl3 = "Now d is not an accepted answer!",
	tl4 = "There can also be 9 lines of text.",
	tl5 = "DERP",
	tl6 = "DERPTEST",
	tl7 = "HERPATEST",
	tl8 = "YOU ARE PARTICIPATING IN A TEST!",
	tl9 = "END OF TEST I AM GOING TO SEE HOW FAR THIS GOES esiurlsbwsehtewjhlwiuhtjnkwnhwunthwnhlkwjuhuwshouwehbouwbhpouhgerouwhbpohebouhbtoiuewhbtpowehblewsjheorhgouwhgljwfdhglkjdhgkjdshgkdshgskdjhgskjfhglkfdsjhglskdjhgsldkfjhgsldkfjhgslkfdghlkdshgsdlkghslkjfdghsdlkfglkpeniscv,mnv,mcxvprrugtiehbrjndf,mn lkjshlhbsldbnslkdblsdnbsdnbsnjbnkjdrsorabr Pretty far. Paragraph go real long, though.",
	qa = "blargh",
	qb = "targ",
	qc = "farg",
	daccept = false,
	anext = qset6,
	bnext = qset7,
	cnext = qset8,}
qset3 = {
	tl1 = "I already know this can do up to 9 lines, as tested.",
	tl2 = "a or b, please.",
	qa = "ANSWER A!",
	qb = "ANSWER B!",
	caccept = false,
	daccept = false,
	anext = qset9,
	bnext = qset10,}
qset4 = {
	tl1 = "qset4",
	tl2 = "abc",
	qa = "AAA",
	qb = "BBB",
	qc = "CCC",
	daccept = false,
	anext = qset11,
	bnext = qset12,
	cnext = qset13}
qset5 = {
	tl1 = "qset5",
	tl2 = "abcd",
	qa = "answer a",
	qb = "answer b",
	qc = "answer c",
	qd = "answer d",
	anext = qset14,
	bnext = qset15,
	cnext = qset16,
	dnext = qset17,}
qset6 = {
	tl1 = "qset6",
	tl2 = "ab",
	caccept = false,
	daccept = false,
	qa = "answer a",
	qb = "answer b",
	anext = qset18,
	bnext = qset19,}
curset = qset1
stop = stop + 1
until stop == 10
stop = nil
repeat
print(curset.tl1)
if curset.tl2 ~= nil then print(curset.tl2) end
if curset.tl3 ~= nil then print(curset.tl3) end
if curset.tl4 ~= nil then print(curset.tl4) end
if curset.tl5 ~= nil then print(curset.tl5) end
if curset.tl6 ~= nil then print(curset.tl6) end
if curset.tl7 ~= nil then print(curset.tl7) end
if curset.tl8 ~= nil then print(curset.tl8) end
if curset.tl9 ~= nil then print(curset.tl9) end
repeat
repeat
input = io.read()
if input == "c" and curset.caccept == false then
	input = nil
end
if input == "d" and curset.daccept == false then
	input = nil
end
if input ~= "a" and input ~= "b" and input ~= "c" and input ~= "d" then
	print("That is not an acceptable answer.")
end
until input == "a" or input == "b" or input == "c" or input == "d"
if input == "a" then
	print(curset.qa)
	curset = curset.anext
	thing = true
	print()
end
if input == "b" then
	print(curset.qb)
	curset = curset.bnext
	thing = true
	print()
end
if input == "c" then
	print(curset.qc)
	curset = curset.cnext
	thing = true
	print()

end
if input == "d" then
	print(curset.qd)
	curset = curset.dnext
	thing = true
	print()
end
until thing == true
thing = nil
until win == true
This does what I want it to (That being switching from one table to the next, printing text, receiving input, etc.). It does this once.

Then it breaks D:

Somehow, it sets a variable to nil, despite me not telling it to do that, and not asking to define itself as something that doesn't exist.

How does fix?
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: Help with Lua

Post by Santos »

At the start of the main loop, curset is qset1.
Let's say the user enters "c", curset = curset.cnext, which means curset is qset1.cnext, which means curset is qset4.
Let's say the user enters "c" again, curset = curset.cnext, which means curset is qset4.cnext, which means curset is qset13, but qset13 doesn't exist.

Hope this helps! :)
User avatar
Rhinoceros
Prole
Posts: 35
Joined: Mon Jun 11, 2012 2:59 am
Location: Under the Floorboards

Re: Help with Lua

Post by Rhinoceros »

Oh.

Well.

Now I feel kinda stupid.

But, it is fixed, thank you good sir.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest