Jump to content

[Help] I can't export


Kazafka

Recommended Posts

  • Moderators
13 minutes ago, VaporZ said:

So IIYAMA, what can I do here, to make it work in same resource?

Just call it, you defined the variable/function as a global, therefore it is not bound to the file scope.

rgbOpenPicker()

 

After the onClientResource event has been triggered, you know for sure that all global variables are available everywhere. (All files have been loaded)

Edited by IIYAMA
Link to comment
2 minutes ago, IIYAMA said:

After the onClientResource event has been triggered, you know for sure that all global variables are available everywhere. (All files have been loaded)

So, this will work?

CLIENT-SIDE 1:

addEventHandler("onClientResourceStart", resourceRoot, function()
    --Define function rgbOpenPicker()
    function rgbOpenPicker()
      --Do some GUI stuff
    end
end)

CLIENT-SIDE 2:

--Call for defined function, earlier
rgbOpenPicker()

 

Link to comment
3 minutes ago, IIYAMA said:

No, you are calling the function before it is created.

Move the event stuff to clientside 2, so that you can delay the call and not the creation time.

So,

CLIENT-SIDE 1:

addEventHandler("onClientResourceStart", resourceRoot, function()
    --Define function rgbOpenPicker()
    function rgbOpenPicker()
      --Do some GUI stuff
    end
end)

CLIENT-SIDE 2:

addEventHandler("onClientResourceStart", resourceRoot, function()
    --Define function rgbOpenPicker()
    function rgbOpenPicker()
      --Do some GUI stuff
    end
end)

rgbOpenPicker()

But u know, that I have GUI only in CLIENT-SIDE 1, so doing the same in CLIENT-SIDE 2 with nil values, is weirdo

Edited by VaporZ
Link to comment
1 minute ago, IIYAMA said:

Just 2 files

If it is 1 or 2 doesn't really matter when using the event onClientResourceStart.

 

So, when I  want to call for a function from client-side1.Lua, wich is wrote in other script, like client-side2.Lua   I need to do this?   Or e x p o r t  ?

Link to comment
  • Moderators
29 minutes ago, VaporZ said:

like client-side2.Lua   I need to do this?   Or e x p o r t  ?

Export is used only when you have 2 (or more) separated resources.

So for example:

- admin (resource 1)

- editor (resource 2)

- freeroam (resource 3)

 

If you have only 2 files within 1 resource, then yes that is the way to go from my previous post

 

Edited by IIYAMA
Link to comment
26 minutes ago, VaporZ said:

So, when I  want to call for a function from client-side1.Lua, wich is wrote in other script, like client-side2.Lua   I need to do this?   Or e x p o r t  ?

Dude its not hard , your basically just calling back the function

 

function InEDYoU()
guiSetVisible(window, true)
showCursor(true, true)
end
addEventHandler("onClientResourceStart", resourceRoot, function()
inEDYoU()----- calls the function
end)

 

Link to comment
3 minutes ago, IIYAMA said:

If you have only 2 files within 1 resource, then yes that is the way to go from my previous post

But im trying  in one resource:

CLIENT-SIDE    1:

--Define  function
function  rgbOpenPicker()
  --GUI magic
end

CLIENT-SIDE 2:

rgbOpenPicker()

And dont  work. What  is wrong then.

Link to comment
1 minute ago, IIYAMA said:

Show me your meta.xml (+ let me know which file contains which code)

META:

<meta>
	<export function="dxDrawTextOnElem" type="server"/>
	
	<!---->
	
	<script src="cars.Lua" type="server"/>
	
	<script src="bank.Lua" type="server"/>
	
	<script src="utility.Lua" type="server"/>
	<script src="utility-c.Lua" type="client"/>
	<script src="3dmessages.Lua" type="client"/>
	
	<script src="testy.Lua" type="server"/>
	<script src="testy-c.Lua" type="client"/>
	
	<script src="rgbpicker/gui.Lua" type="client"/>
	
	<!---->
	
	<file src="bank/accounts.xml"/>
	<file src="bank/atms.xml"/>
	
	<file src="cars/saved.xml"/>
	<file src="cars/shops.xml"/>
	
	<!---->
	
	<info author="VaporZ" name="VaporZ's utility [PL]" description="Utility od VaporZ (po polsku)" type="script" version="1.0.1"/>
</meta>

GUI.Lua:

function rgbClosePicker(button, state) --Funkcja zamykająca wybieranie kolorków, +zwracająca ich wartości (poprzez event "rgbOnColorsPicked", parametry: r (czerwony), g (zielony), b (niebieski))
	if(button == "left") and (state == "up") then
		local pos1 = guiScrollBarGetScrollPosition(scrollbar1)
		local pos2 = guiScrollBarGetScrollPosition(scrollbar2)
		local pos3 = guiScrollBarGetScrollPosition(scrollbar3)
		guiSetVisible(window, false)
		showCursor(false, false)
		local red = pos1
		local green = pos2
		local blue = pos3
		local red = red * 255 / 100
		local green = green * 255 / 100
		local blue = blue * 255 / 100
		triggerEvent("rgbOnColorsPicked", resourceRoot, red, green, blue)
	end
end

function OnScroll()
	local pos1 = guiScrollBarGetScrollPosition(scrollbar1)
	local pos2 = guiScrollBarGetScrollPosition(scrollbar2)
	local pos3 = guiScrollBarGetScrollPosition(scrollbar3)
	local red = pos1
	local green = pos2
	local blue = pos3
	local red = red * 255 / 100
	local green = green * 255 / 100
	local blue = blue * 255 / 100
	guiLabelSetColor(label4, red, green, blue)
end

addEventHandler("onClientResourceStart", resourceRoot, function() --Generowanie interfejsu
		
	local screenW, screenH = guiGetScreenSize()
	window = guiCreateWindow((screenW - 337) / 2, (screenH - 224) / 2, 337, 224, "Wybierz kolor w formacie RGB", false)
	guiWindowSetSizable(window, false)

	scrollbar1 = guiCreateScrollBar(9, 29, 318, 15, true, false, window)
	scrollbar2 = guiCreateScrollBar(10, 79, 317, 15, true, false, window)
	label1 = guiCreateLabel(123, 54, 93, 15, "R (czerwony)", false, window)
	guiLabelSetColor(label1, 255, 0, 0)
	guiLabelSetHorizontalAlign(label1, "center", false)
	label2 = guiCreateLabel(128, 104, 82, 15, "G (zielony)", false, window)
	guiLabelSetColor(label2, 0, 255, 0)
	guiLabelSetHorizontalAlign(label2, "center", false)
	scrollbar3 = guiCreateScrollBar(10, 129, 317, 15, true, false, window)
	label3 = guiCreateLabel(123, 154, 93, 18, "B (niebieski)", false, window)
	guiLabelSetColor(label3, 0, 0, 255)
	guiLabelSetHorizontalAlign(label3, "center", false)
	button1 = guiCreateButton(10, 182, 158, 32, "Wybierz", false, window)
	label4 = guiCreateLabel(179, 186, 148, 22, "Przykładowy tekst", false, window)
	guiLabelSetHorizontalAlign(label4, "center", false)

	addEventHandler("onClientGUIClick", button1, rgbClosePicker, false)
	addEventHandler("onClientGUIScroll",getRootElement(),OnScroll)
	
	guiSetVisible(window, false)
	showCursor(false, false)
	
	function rgbOpenPicker(bool) --Funkcja otwierająca wybieranie kolorków
		guiSetVisible(window, true)
		showCursor(true, true)
	end
	
	addCommandHandler("rgb", function()
		rgbOpenPicker()
	end)
end)

function rgbToHex(red, green, blue, alpha) --Funkcja formatująca kolor w formacie RGB na kolor w formacie HEX (r, g, b, a --> FFRRGGBBAA)
	if((red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255) or (alpha and (alpha < 0 or alpha > 255))) then
		return nil
	end
	if alpha then
		return string.format("FF%.2X%.2X%.2X%.2X", red, green, blue, alpha)
	else
		return string.format("FF%.2X%.2X%.2X", red, green, blue)
	end
end

TESTY-C.Lua:

exports[getResourceName(getThisResource())]:rgbOpenPicker(true)  or rgbOpenPicker()

addEvent("rgbOnColorsPicked", true)
addEventHandler("rgbOnColorsPicked", resourceRoot, function(r, g, b)
	outputChatBox("Oto te kolorki!", r, g, b)
end)

 

Link to comment
  • Moderators

A lot of clean up has to be done.

Oke the first thing I want to mention is this:

 <script src="testy-c.Lua" type="client"/>   	
<script src="rgbpicker/gui.Lua" type="client"/>

The test script is loaded first, therefore it is executed first. Which means that you are calling the function rgbOpenPicker, which has not been created yet. So you might want to switch that order or add the onClientResourceStart event, which will wait until all scripts have been loaded.

 

Next:

exports[getResourceName(getThisResource())]:rgbOpenPicker(true)  or rgbOpenPicker()

Please follow my instructions. This experiment was not included, please do reset that back before continuing and iterating.

 

 

Next:

rgbOpenPicker("left", "up")

If you are using arguments, then make sure to fill them in.

 

Last thing, add debug lines, just for me please?

 

 

 

Link to comment
41 minutes ago, IIYAMA said:

A lot of clean up has to be done.

Oke the first thing I want to mention is this:


 <script src="testy-c.Lua" type="client"/>   	
<script src="rgbpicker/gui.Lua" type="client"/>

The test script is loaded first, therefore it is executed first. Which means that you are calling the function rgbOpenPicker, which has not been created yet. So you might want to switch that order or add the onClientResourceStart event, which will wait until all scripts have been loaded.

Clean-up - Not already done

Changed order of scripts - Done

Filling arguments - ?Deleted arguments?

Still none of effect :( 

Link to comment
  • Moderators
2 hours ago, VaporZ said:

Filling arguments - ?Deleted arguments?

 

Yes, your script is passing over arguments that are used within the rgbOpenPicker as parameters.

 

In:

rgbOpenPicker("left", "up")

 

Out:

function rgbClosePicker(button, state) 
  
	--[[ ... ]]
  
	iprint(button) -- outputs "left"
	iprint(state) -- outputs "up"
  
	--[[ ... ]]

 

 

2 hours ago, VaporZ said:

Still none of effect :( 

 

For you the definition of an effect is apparently: Everything works fine!

Which is for me not really useful, if it is positive, it only means that I do not have to help you any more.

 

The effects that are relevant for me are:

  • Are there errors/warnings from this script?
  • Is this, this, this and this code executed?
  • Are the values of a variable correct?

And how would I get that relevant information? That is where you come in! So please help me too.

Debug the code for me!

 

 

 

 

Link to comment

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.
×
×
  • Create New...