Jump to content




GUI API doesent work


12 replies to this topic

#1 Wilma456

  • Members
  • 187 posts
  • LocationGermany

Posted 24 June 2016 - 01:16 PM

I have coded a gui api to mode a scrollable menu (the scrolling is not implement at the moment). But the clickaable menus doesent work.

Code
Print shows me the right variable. And if I write getfenv()["print"]("test") ist works. Wheres the problem?

#2 The_Cat

  • Members
  • 119 posts

Posted 24 June 2016 - 03:04 PM

You havn't linked the API, but is 'getfenv()' in that API? If so you need to call it with gui infront of it. Like how it says on the 3rd line gui.create... etc.

#3 Wilma456

  • Members
  • 187 posts
  • LocationGermany

Posted 24 June 2016 - 03:22 PM

View PostThe_Cat, on 24 June 2016 - 03:04 PM, said:

You havn't linked the API, but is 'getfenv()' in that API? If so you need to call it with gui infront of it. Like how it says on the 3rd line gui.create... etc.
Wenn I wrote getfenv()["print"]("test") it works. Thats not the problem.

#4 The_Cat

  • Members
  • 119 posts

Posted 24 June 2016 - 03:52 PM

My bad. 'getfenv()' doesn't exist as far as I can tell so it will error there anyway. As for the problem at hand, I'm not 100% sure what you mean, is it because you cannot click on the buttons separately and have different outcomes for the two? If so you will need to store the X and Y positions of the buttons. You can then use those positions to check with where the user clicked.

Edited by The_Cat, 24 June 2016 - 04:14 PM.


#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 25 June 2016 - 01:17 AM

You haven't bothered to specify, but I imagine you get an "attempt to index nil" on this line:

getfenv()[srollrun[y][mouse]](scrollarg[y][mouse])--(scrollarg[y][mouse])

... because you haven't defined a "srollrun".

This line a little higher up isn't relevant to your immediate problem, but also needs correction:

getfenv()[scrollrun[mouse][y+1]](scrollarg[mouse][y+1])

... as you've got the table indexes the wrong way around.

If you're still having problems, explain what the script DOES do.

#6 Wilma456

  • Members
  • 187 posts
  • LocationGermany

Posted 25 June 2016 - 11:40 AM

View PostBomb Bloke, on 25 June 2016 - 01:17 AM, said:

You haven't bothered to specify, but I imagine you get an "attempt to index nil" on this line:

getfenv()[srollrun[y][mouse]](scrollarg[y][mouse])--(scrollarg[y][mouse])

... because you haven't defined a "srollrun".

This line a little higher up isn't relevant to your immediate problem, but also needs correction:

getfenv()[scrollrun[mouse][y+1]](scrollarg[mouse][y+1])

... as you've got the table indexes the wrong way around.

If you're still having problems, explain what the script DOES do.

thankyou

But i have a new question:
If there any better way to use function in tje runing program as to code a function in the api who just runs os.loadAPI?
--Exampele
--Best way to call the func test
function test()
   print("test")
end
os.loadAPI("/lib/gui")
gui.createScroll("Hello")
gui.addScrollFunc("test","hello",1)
gui.createScroll("world")
gui.addScrollFunc("print","world",1)
gui.drawScroll()


#7 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 25 June 2016 - 12:13 PM

--Exampele
--Best way to call the func test
function test()
   print("test")
end
os.loadAPI("/lib/gui")
gui.createScroll("Hello")
gui.addScrollFunc(test,"hello",1) --#this passes the actual function, rather than a string, as an argument.
gui.createScroll("world")
gui.addScrollFunc("print","world",1)
gui.drawScroll()


#8 Wilma456

  • Members
  • 187 posts
  • LocationGermany

Posted 25 June 2016 - 12:44 PM

View PostKingofGamesYami, on 25 June 2016 - 12:13 PM, said:

--Exampele
--Best way to call the func test
function test()
   print("test")
end
os.loadAPI("/lib/gui")
gui.createScroll("Hello")
gui.addScrollFunc(test,"hello",1) --#this passes the actual function, rather than a string, as an argument.
gui.createScroll("world")
gui.addScrollFunc("print","world",1)
gui.drawScroll()

This doesent works

#9 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 25 June 2016 - 12:58 PM

View PostWilma456, on 25 June 2016 - 12:44 PM, said:

View PostKingofGamesYami, on 25 June 2016 - 12:13 PM, said:

--Exampele
--Best way to call the func test
function test()
print("test")
end
os.loadAPI("/lib/gui")
gui.createScroll("Hello")
gui.addScrollFunc(test,"hello",1) --#this passes the actual function, rather than a string, as an argument.
gui.createScroll("world")
gui.addScrollFunc("print","world",1)
gui.drawScroll()
This doesent works

How are you using the argument (function)?

#10 Wilma456

  • Members
  • 187 posts
  • LocationGermany

Posted 25 June 2016 - 01:06 PM

View PostMKlegoman357, on 25 June 2016 - 12:58 PM, said:

View PostWilma456, on 25 June 2016 - 12:44 PM, said:

View PostKingofGamesYami, on 25 June 2016 - 12:13 PM, said:

--Exampele
--Best way to call the func test
function test()
print("test")
end
os.loadAPI("/lib/gui")
gui.createScroll("Hello")
gui.addScrollFunc(test,"hello",1) --#this passes the actual function, rather than a string, as an argument.
gui.createScroll("world")
gui.addScrollFunc("print","world",1)
gui.drawScroll()
This doesent works

How are you using the argument (function)?

in this function, the argument are not used, Its only there, because I had no errors.

#11 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 25 June 2016 - 01:43 PM

View PostWilma456, on 25 June 2016 - 01:06 PM, said:

in this function, the argument are not used, Its only there, because I had no errors.

I'm talking about the 'gui.addScrollFunc()' function. What is it doing? How is it using the function 'test'? You can treat functions just like any other variable. For example:

local function hello ( name )
  print( "Hello, " .. name .. "!" )
end

local function foo ( fn )
  fn( "World" )
end

foo( hello ) --> Hello, World!

Edited by MKlegoman357, 25 June 2016 - 01:43 PM.


#12 Wilma456

  • Members
  • 187 posts
  • LocationGermany

Posted 25 June 2016 - 03:58 PM

View PostMKlegoman357, on 25 June 2016 - 01:43 PM, said:

View PostWilma456, on 25 June 2016 - 01:06 PM, said:

in this function, the argument are not used, Its only there, because I had no errors.

I'm talking about the 'gui.addScrollFunc()' function. What is it doing? How is it using the function 'test'? You can treat functions just like any other variable. For example:

local function hello ( name )
  print( "Hello, " .. name .. "!" )
end

local function foo ( fn )
  fn( "World" )
end

foo( hello ) --> Hello, World!

After you add a text with with gui.createScroll() You can add a funcktion to this text. For example:
gui.craeteScroll("text")
gui.addScrollFunc("print","hello world",1)
if you run this code, you get the text "text". If you clickk on the text "text" it runs print("hello world").

#13 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 25 June 2016 - 04:36 PM

Like KingofGamesYami suggested, just pass the actual function and then call it like in my example.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users