Jump to content
  • 0

how to preform action when gg button is clicked?


animehack

Question

so basiclly i want to execute a function when the yser clicks the game guardian icon i tryed to use gg.isClickedUiButton but it dident seem to work i prob just used it wrong i tryed reading the documentation but dident relly help me anyone can help me with a alternative methood?

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

9 hours ago, animehack said:

so basiclly i want to execute a function when the yser clicks the game guardian icon i tryed to use gg.isClickedUiButton but it dident seem to work i prob just used it wrong i tryed reading the documentation but dident relly help me anyone can help me with a alternative methood?

You could go with the @MonkeySAN method. But if you call any other function than Main( ) or whatever you named your Main Menu function. You'll need to call Main( ) somewhere inside the function that you called at loop to keep showing the menu...

And it could go wrong if you ONLY want to call this function once, at the beggining of the script.

 

So let's approach it differently... If you see, the loop function lies at the bottom of your script, which means that when a script is initialized, GG will read ALL the script and then when it reachs the loop part, it sees the call Main( ) and goes up to function Main()

So you could go like this to execute ONLY ONCE after starting the script

function Main()
  
  executedOnce = 0 -- Set a variable with an int value
  if executedOnce == 0 then
    executedOnce = 1 -- Change the variable to prevent re-executing everytime GG is pressed
    function executeOnceWhenGGPressed() -- Set your function to execute
      -- Code to run
    end
    executeOnceWhenGGPressed() -- Run the function
  end
  
  -- Your menu and code...
  
end

Or like this to execute EVERY SINGLE TIME when GG is pressed

function Main()
  
  -- No need for a variable neither an IF statement
    function executeWhenGGPressed() -- Set your function to execute
      -- Code to run
    end
    executeWhenGGPressed() -- Run the function everytime GG is pressed
  
  -- Your menu and code...
  
end

 

Hope it helped!

Link to comment
Share on other sites

i have this idea...

1.Open GG

2.Open script

3.Alert box appear with some infos to user --> alert box close

4.Only GG icon visible

5.User tap GG icon --> execute 1st hack in the script --> done

6.Only GG icon Visible

7.User tap GG icon again --> execute 2nd hack in the script -- > done

8.Only GG icon visible

9.User tap GG icon again

10.Alert box appear with 3 options :

      -[EXIT] the script.

      -[CLOSE] do nothing but will execute         [START] once press after that.

      -[START] from no.5 again right away.

is it posibble?

hope you can understand.

Thanks.

 

Link to comment
Share on other sites

ok thx for your reply @MonkeySAN and @RCPOLSKI but its not exactly what i am looking for. ok here is my code

while true do
	if Qjctx == 1 then
		if loader123 then
			loader123()
		end
	elseif Qjctx == 2 then
           if main then
	          main()
	      end
	elseif Qjctx == 3 then
	       if gg.setVisible(true) then
	           ::notClicked::
	              gg.setVisible(false)
	              gg.isClickedUiButton(false)
	              if gg.isClickedUiButton(false) then
	                 goto notClicked
	              end
	       else
	          Qjctx = 2
	          if main then
	             main()
	          end
	       end
	end
end

so i define at the top of my script that Qjctx is = to 1 so it will start me off with loading the function loader123() then in loader123() i have it execute another function that sets Qjctx = to 2 so then it will load main and after that i have nothing more ssying Qjctx is = to 1 so you can ignore that and in the main() function i have it set so if the user presses nil insted of a hack Qjctx is = to 3 and so if you read my code you will see that i tryed to setVisible to false so basiclly temporarily close the menu and then i tryed doing a goto loop with gg.isClickedUiButton but it dident relly work as i wanted it to i think this will help clear up what i am trying to do if not please leave a comment and i will try and explain in another way 

Link to comment
Share on other sites

9 hours ago, animehack said:

so i define at the top of my script that Qjctx is = to 1 so it will start me off with loading the function loader123() then in loader123() i have it execute another function that sets Qjctx = to 2 so then it will load main and after that i have nothing more ssying Qjctx is = to 1 so you can ignore that and in the main() function i have it set so if the user presses nil insted of a hack Qjctx is = to 3 and so if you read my code you will see that i tryed to setVisible to false so basiclly temporarily close the menu and then i tryed doing a goto loop with gg.isClickedUiButton but it dident relly work as i wanted it to i think this will help clear up what i am trying to do if not please leave a comment and i will try and explain in another way 

if gg.setVisible(true) then -- If GG UI is visible then
	::notClicked:: -- COME HERE AFTER YOU READ ALL
	gg.setVisible(false) -- Set it to false, ok
	gg.isClickedUiButton(false) -- Then you try to set it to false too. But isClickedUiButton is a comparer. You cant set it to false or true, ONLY return its value
	if gg.isClickedUiButton(false) then -- Then here, you ask if the isClickedUiButton is false
		goto notClicked -- IF SO, GO TO LINE TWO AND READ EVERY LINE AGAIN. See the error?
end

Your code is a mess, you don't really know what you're doing... Like, what is the reason? It looks like you're trying to force a loop in someone that has NOT agreed to it

Anyways, here it go. EXACTLY AS YOU DESCRIBED ABOVE!!!!

Qjctx = 1 -- Starting with qjctx set to 1

function loader123()

    if Qjctx == 1 then
        Qjctx = 2 -- No need to a "ANOTHER FUNCTION" to change it, just change it if the statement confirms it is = 1!
        Main() -- Just call Main after setting qjctx to 2
    elseif Qjctx == 2 then
        Main() -- If qjctx is 2, then just call Main()
    elseif Qjctx == 3 then
        -- Here I don't know wtf you're trying to do...
    	gg.setVisible(false) -- if you want to hide the GG UI, just do it
    end

end

function Main()

    menu = gg.choice({
        'Cheat',
        'Another One',
        'One more'
    }, nil)

    if menu == 1 then cheatOne() end -- Calls cheat 1
    if menu == 2 then cheatTwo() end -- 2
    if menu == 3 then cheatThr() end -- 3
    if menu == nil then -- If player presses 'cancel' or outside the window = nil. Set qjctx to 3 and call Loader123() to apply its power
        Qjctx = 3 
        loader123()
    end  

end

gg.setVisible(true)
while true do
if gg.isVisible() then
   gg.setVisible(false)
   loader123() -- Always call loader123 function instead of Main()
   end
   gg.sleep(100)
end

 

If you're really trying to force a loop cuz the player didnt pressed anything. STOP! It's a bad decision that YOU ARE NOT ALLOWED to do over someone's phone!

Link to comment
Share on other sites

2 hours ago, RCPOLSKI said:

if gg.setVisible(true) then -- If GG UI is visible then
	::notClicked:: -- COME HERE AFTER YOU READ ALL
	gg.setVisible(false) -- Set it to false, ok
	gg.isClickedUiButton(false) -- Then you try to set it to false too. But isClickedUiButton is a comparer. You cant set it to false or true, ONLY return its value
	if gg.isClickedUiButton(false) then -- Then here, you ask if the isClickedUiButton is false
		goto notClicked -- IF SO, GO TO LINE TWO AND READ EVERY LINE AGAIN. See the error?
end

Your code is a mess, you don't really know what you're doing... Like, what is the reason? It looks like you're trying to force a loop in someone that has NOT agreed to it

Anyways, here it go. EXACTLY AS YOU DESCRIBED ABOVE!!!!


Qjctx = 1 -- Starting with qjctx set to 1

function loader123()

    if Qjctx == 1 then
        Qjctx = 2 -- No need to a "ANOTHER FUNCTION" to change it, just change it if the statement confirms it is = 1!
        Main() -- Just call Main after setting qjctx to 2
    elseif Qjctx == 2 then
        Main() -- If qjctx is 2, then just call Main()
    elseif Qjctx == 3 then
        -- Here I don't know wtf you're trying to do...
    	gg.setVisible(false) -- if you want to hide the GG UI, just do it
    end

end

function Main()

    menu = gg.choice({
        'Cheat',
        'Another One',
        'One more'
    }, nil)

    if menu == 1 then cheatOne() end -- Calls cheat 1
    if menu == 2 then cheatTwo() end -- 2
    if menu == 3 then cheatThr() end -- 3
    if menu == nil then -- If player presses 'cancel' or outside the window = nil. Set qjctx to 3 and call Loader123() to apply its power
        Qjctx = 3 
        loader123()
    end  

end

gg.setVisible(true)
while true do
if gg.isVisible() then
   gg.setVisible(false)
   loader123() -- Always call loader123 function instead of Main()
   end
   gg.sleep(100)
end

 

If you're really trying to force a loop cuz the player didnt pressed anything. STOP! It's a bad decision that YOU ARE NOT ALLOWED to do over someone's phone!

ok after reading your msg i thought about it and your right i should not be forcing loops and yeh ig my code was a mess but after thinking simpler i found out a way to fix my problem here is the end result:

do
if Qjctx == 1 then
			loader123()
		end
end

gg.setVisible(true)
while true do
if gg.isVisible() then
   gg.setVisible(false)
   main()
   Qjctx = 2
   end
   gg.sleep(100)
end

this way i can execute the loader123() function and then always go to main() thx

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.