Jump to content

Recommended Posts

hello,

i have a question regarding the global tables that used in a quest,

for example if i want to use a table named: 

TableTest = { }

i tried to initialize it here:
 

when 20355.chat."Initialize Table" begin
	TableTest = { }

	TableTest[1] = {
		name = nil,
  		point = 0,
	}
end

now it should be good to be used globally through the quest right ?
 

but when i try to call it let's say if a player killed or left:

when 20355.chat."Accept" begin
	if (TableTest[1].name == nil) then
		TableTest = {
			name = pc.getname(),
			point = 0,
		}
	end
end

when kill begin
	if pc.get_map_index() == 21 then
		if (TableTest and TableTest[1].name == pc.getname()) then
			TableTest[1].point = TableTest[1].point + 1
			syschat ("You earned the point.")
		end
	end
end



it won't work it keeps giving me this error:
 

attempt to index global `challenges' (a nil value)

 

i don't why it's not recognize the table for some reason, can someone help pls, thanks.

Link to comment
https://metin2.dev/topic/33770-global-table-in-quest/
Share on other sites

questlib.lua

your_table = {

 

}

then you can use your_table across all the quests

when kill begin
	if pc.get_map_index() == 21 then
		if (your_table and your_table[1].name == pc.getname()) then
			your_table[1].point = your_table[1].point + 1
			syschat ("You earned the point.")
		end
	end
end

 

Edited by A Man Has No Name
Link to comment
https://metin2.dev/topic/33770-global-table-in-quest/#findComment-171027
Share on other sites

  • Honorable Member

Personally, the rule of thumb when questing is that if the first thing that comes to your mind when trying to solve an issue is to use a global array, either you might want to rethink it and do it differently, or it's not a thing that should be done via quest in the first place at all.

In the case you presented, you're better off using a sql table to handle eventual ranking points while registering names and stuff.

 

  • Good 1

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
https://metin2.dev/topic/33770-global-table-in-quest/#findComment-171038
Share on other sites

9 hours ago, A Man Has No Name said:

questlib.lua

your_table = {

 

}

then you can use your_table across all the quests

when kill begin
	if pc.get_map_index() == 21 then
		if (your_table and your_table[1].name == pc.getname()) then
			your_table[1].point = your_table[1].point + 1
			syschat ("You earned the point.")
		end
	end
end

 

 

thanks for your reply, i think i tried that before and i got the same error that is not defined or something,
i'll try it again and tell you about it.

 

29 minutes ago, Syreldar said:

Personally, the rule of thumb when questing is that if the first thing that comes to your mind when trying to solve an issue is to use a global array, either you might want to rethink it and do it differently, or it's not a thing that should be done via quest in the first place at all.

In the case you presented, you're better off using a sql table to handle eventual ranking points while registering names and stuff.

 

Yes you're right, what i want to do could definitely be implemented more effectively in C++.
But at the same time, i don't think it's so complex that it can't be done through a quest, since all i really need is a simple table to store the players ids and track their points, nothing more, Thanks for your reply.

i also thought about using sql table at the end, i was like if i didn't find any solution for this one i'll go for the sql table instead.

Link to comment
https://metin2.dev/topic/33770-global-table-in-quest/#findComment-171041
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.