This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
XoX's profile picture

Table acting weird

Started by XoX, 30 October 2012 - 07:54 PM
XoX #1
Posted 30 October 2012 - 08:54 PM
SpoilerI doubt that any of you have the time to read through this script and understand what I'm trying to do.
Anyways, my problem is that I can't call any of exec functions in menu2 .
When I call for example menu2[1].exec() it doesn't do anything at all, if I take one of the items in menu2 and put them in menu3 they work fine.

http://pastebin.com/kYzPYvV9

I know it's not tabbed, I might later but I code partially in game I can't tab.

EDIT:
I fixed the problem, for some reason as soon as I copy menu2 to menu5 it for some reason messes up menu2,
I don't know what the reason is for this and if this is still a problem in the current version of Computercraft but it should definitely be fixed.
Edited on 30 October 2012 - 08:26 PM
Cloudy #2
Posted 31 October 2012 - 02:59 AM
Of course it is still an issue in the latest version of ComputerCraft - because it is your code which is a problem. Because you're altering the functions in the sub tables of menu2 after referencing them from menu5, the functions in menu2 instead do the actions in menu5.
XoX #3
Posted 31 October 2012 - 09:20 AM

for k, v in ipairs(menu5) do
I am editing in the table menu5, not menu2.

And I am not doing menu5 = menu2 as before which apparenly is supposed to reference to the old table.
I wrote a table.copy function which SHOULD create a copy of the table, not a reference.

EDIT: WAIT, don't tell me that because the contents of the table are tables I'm not copying the table but referencing the sub-tables in the old table instead of creating them in the new table??


EDIT2: Should this work then?

ttable.copy = ""
ttable.copy = function(t1)
	local t2 = {}
	for k,v in pairs(t1) do
		if type(v) == "table" then
			t2[k] = ttable.copy(v)
		else
			t2[k] = v
		end
	end
	return t2
end
Cloudy #4
Posted 31 October 2012 - 07:18 PM
That's exactly what I was dating saying :P/>/>

Yep the new code should do what is expected.
XoX #5
Posted 31 October 2012 - 09:38 PM
That's exactly what I was dating saying :P/>/>

Yep the new code should do what is expected.

Sweet, alright.
I had no idea that if you try to assign a variable the value of a defined table it would just refer to it.


I was wondering, what do you have to do to get the Lua Coder Pro whatever tag?
Lyqyd #6
Posted 31 October 2012 - 10:55 PM
There's no set rule on getting marked as a Pro. Setting out to try to get it just because it's shiny isn't the way to earn it, though.
ChunLing #7
Posted 31 October 2012 - 11:09 PM
I was marked as a pro for a while. Now I'm on the road to back-alley Lua serial offender. Which is kinda the wrong direction, from a certain point of view.
Lyqyd #8
Posted 31 October 2012 - 11:12 PM
I was marked as a pro for a while. Now I'm on the road to back-alley Lua serial offender. Which is kinda the wrong direction, from a certain point of view.

The "Lua Pros" group is separate from the post count rank names. :P/>/>
ChunLing #9
Posted 31 October 2012 - 11:46 PM
True. But if you check, "Lua Coder Pro" is probably talking about the Coder Pro tag, or at least failing to distinguish it from Lua Pro. Just saying that as one on the path to becoming a Dark Lord of Aul.
XoX #10
Posted 01 November 2012 - 12:05 AM
I meant the Lua Pro tag, I just couldn't recall what it was called exactly.
I was just wondering.