Jump to content

text inside a label moves from right to left?


Recommended Posts

Posted

Hi, i creates a GUI with the GUI Editor, and now i want that the text in a label moves from right to left, but not the label itself!

Is that possibly? I think it is anything with this math. stuff in lua, but i absolutely don´t know how i can make that.

Here is the label:

label = guiCreateLabel(0.019390568137169,0.39655232429504,0.9570637345314,0.34482741355896,xmlInfoData,true,GUIEditor_Window[1]) 

You can see the script read the text for the label out from a xml file, and that´s works perfect! but i want to let it move :)

I hope you understand me :wink:

Posted

Hi, i creates a GUI with the GUI Editor, and now i want that the text in a label moves from right to left, but not the label itself!

Is that possibly? I think it is anything with this math. stuff in lua, but i absolutely don´t know how i can make that.

Here is the label:

label = guiCreateLabel(0.019390568137169,0.39655232429504,0.9570637345314,0.34482741355896,xmlInfoData,true,GUIEditor_Window[1])

You can see the script read the text for the label out from a xml file, and that´s works perfect! but i want to let it move :)

I hope you understand me :wink:

Posted

You need to use onClientRender (this event is triggered on every frame) or a timer. Then on every frame get the label's position and set new position by taking away some pixels from X coord. Eg.:

addEventHandler( "onClientRender", getResourceRootElement( getThisResource( ) ), 
    function( ) 
        local x,y = guiGetPosition( label, false ) 
        guiSetPosition( label, x-10, y, false ) 
    end 
) 

You'd have to remake this code a little bit, because this will keep moving the label even if it goes out of screen.

Posted

You need to use onClientRender (this event is triggered on every frame) or a timer. Then on every frame get the label's position and set new position by taking away some pixels from X coord. Eg.:

addEventHandler( "onClientRender", getResourceRootElement( getThisResource( ) ),    function( )        local x,y = guiGetPosition( label, false )        guiSetPosition( label, x-10, y, false )    end)

You'd have to remake this code a little bit, because this will keep moving the label even if it goes out of screen.

Posted

I thank it works absolutely perfect =)

Now i have a other question ^^

First the code:

  
... 
... 
xmlInfo = xmlLoadFile("random_test.xml") 
  
xmlInfoNode = xmlFindSubNode(xmlInfo, math.random(stuff1, stuff3), 0) 
xmlInfoData = xmlNodeGetValue(xmlInfoNode) 
... 
... 
label = guiCreateLabel(0.019390568137169,0.39655232429504,0.9570637345314,0.34482741355896,xmlInfoData,true,GUIEditor_Window[1]) 
... 
... 
  

The label gets the text from an xml file, now i tries to use a math.random to find different nodes in the xml file (line 6 in the code).

I don´t know why but it don´t works, any ideas?

Posted

I thank it works absolutely perfect =)

Now i have a other question ^^

First the code:

 ......xmlInfo = xmlLoadFile("random_test.xml") xmlInfoNode = xmlFindSubNode(xmlInfo, math.random(stuff1, stuff3), 0)xmlInfoData = xmlNodeGetValue(xmlInfoNode)......label = guiCreateLabel(0.019390568137169,0.39655232429504,0.9570637345314,0.34482741355896,xmlInfoData,true,GUIEditor_Window[1])...... 

The label gets the text from an xml file, now i tries to use a math.random to find different nodes in the xml file (line 6 in the code).

I don´t know why but it don´t works, any ideas?

Posted

the second argument of xmlFindSubNode should be a string, math.random returns an integer

in your case it should be

xmlInfoNode = xmlFindSubNode(xmlInfo, "name of subnode", math.random(stuff1, stuff3)) 

Posted

the second argument of xmlFindSubNode should be a string, math.random returns an integer

in your case it should be

xmlInfoNode = xmlFindSubNode(xmlInfo, "name of subnode", math.random(stuff1, stuff3))

Posted

look at the wiki page for xmlFindSubNode

xmlFindSubNode ( xmlnode parent, string subnode, int index ) 

so, based on that, this will search for a subnode of xmlInfo called "name" at a random index

xmlInfoNode = xmlFindSubNode(xmlInfo, "name", math.random(min, max)) 

Posted

look at the wiki page for xmlFindSubNode

xmlFindSubNode ( xmlnode parent, string subnode, int index )

so, based on that, this will search for a subnode of xmlInfo called "name" at a random index

xmlInfoNode = xmlFindSubNode(xmlInfo, "name", math.random(min, max))

Posted

i tested it now:

Here is the lua code:

xmlInfoNode = xmlFindSubNode(xmlInfo, "stuff", math.random(1, 3)) 

And the xml:

<root> 
  
<stuff 1> 
read out from xml file, stuff1 
</stuff 1> 
<stuff 2> 
read out from xml file, stuff2, YEA!! 
</stuff 2> 
<stuff 3> 
and FINALY: read out from xml file, stuff3 
</stuff 3> 
  
</root> 

I also tried it with stuff1, not stuff 1, but don´t works.

I already was thinking about that for my eyes the lua code looks wrong. but i don´t get it working :lol:

Posted

i tested it now:

Here is the lua code:

xmlInfoNode = xmlFindSubNode(xmlInfo, "stuff", math.random(1, 3))

And the xml:

 read out from xml file, stuff11>read out from xml file, stuff2, YEA!!2>and FINALY: read out from xml file, stuff33> 

I also tried it with stuff1, not stuff 1, but don´t works.

I already was thinking about that for my eyes the lua code looks wrong. but i don´t get it working :lol:

Posted

they dont need to have different names, call them all "stuff" and the index will indicate which one to read

also, the index starts at 0 not 1

xmlInfoNode = xmlFindSubNode(xmlInfo, "stuff", math.random(0, 2)) 
  
... 
  
<root> 
<stuff>read out from xml file, stuff1</stuff> 
<stuff>read out from xml file, stuff2, YEA!!</stuff> 
<stuff>and FINALY: read out from xml file, stuff3</stuff> 
</root> 

Posted

they dont need to have different names, call them all "stuff" and the index will indicate which one to read

also, the index starts at 0 not 1

xmlInfoNode = xmlFindSubNode(xmlInfo, "stuff", math.random(0, 2)) ... read out from xml file, stuff1read out from xml file, stuff2, YEA!!and FINALY: read out from xml file, stuff3

Posted

How about making this into a resource? It could be quite useful for server admins in general :)

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...