ipairs() + getResources()

Recommended Posts


Today I was creating a CEGUI based resource system, that would allow easier start/stop of resources. I wanted to make more features, but I won't speak about that.

So, in serverside, I created a function that stores getResources() in a variable, and triggers it to client.

When I loop thru the table in clientside with ipairs(), nothing happens. I tried it with outputChatBox, and nah. No errors in debugscript.

-- server side
addEvent("getResourcesGUI", true)
function resourceGUI ()
	resursi = getResources()

	triggerClientEvent(client, "openGUI", resourceRoot, resursi)
addEventHandler("getResourcesGUI", resourceRoot, resourceGUI)
-- client side
addEvent("openGUI", true)
function init (resursi)
	for k, v in ipairs (resursi) do
		outputChatBox("hi, i spammer 100 resources")
addEventHandler("openGUI", resourceRoot, init)


Oh, and ipairs() work serverside.


So, it doesn't work after passing to client. When I tried to outputChatBox the table ( know its dumb, just to check if it passed ), it shows that it tried to output table, so that's correct. And all events get passed, the serverside gets called by another function, but that's not revelant.

Edited by Gourmet.

Share this post

Link to post

A resource-pointer doesn't exist on clientside - you can't send "resources" to clientside.

You can send resource root elements to clientside, but these will only work if the corresponding resource is running.

Share this post

Link to post

@Gourmet. When I just started scripting I wrote this. You can't send the resources but you can send the data then display that in your gui.

function getResourceData()
	local resources = {}
	local res = getResources()
	for k, resource in ipairs(res) do
		if getResourceInfo(resource, "type") ~= "map" then
			table.insert(resources, {name=getResourceName(resource), state=getResourceState(resource)})
	triggerClientEvent("ResourcesTable", root, resources)

I'm assuming that's what you want.

Edited by Tails
  • Like 1

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.