Using "On click" in the GUI list.

Started by rich, Fri 05/10/2007 11:24:42

Previous topic - Next topic

rich

I couldn't find anything about the GUI "On click" feature in the help file or anything that helped me in the forum archives.

What I'm trying to do, is create code that is activated when you click on a GUI. Not specifically on a button or any specific part of a GUI, but just any part of it. So, it would appear that "On click" is the way to go. It says when I click it "Script function to hand event" followed by a suggusted function called gGUIname_Click where GUIname is the name I gave the GUI. I figured like with the interactions, clicking "OK" would automatically create the function in the Global Script where I could then add the code I wanted. This was not the case. Or, if it was created, I couldn't find it anywhere.

So, I went ahead and created the function myself in the global script.
Started with:

function gGUIName_Click() { ...

and added what I wanted to have happen.

Ran the game. When I clicked the GUI, I got a runtime error:
"wrong number of parameters to exported function 'gGUIName_Click' (expected 0, supplied 2)"

Anyone know what is going on or how I can fix it?
I'm so excited!

Ashen

#1
I have no idea why that's stopped working, but it looks like it has - I tried, and can't even get it to open up to GUI_Click functions I've already created, nevermind create new ones. Fortunately fixing it should be easy, you just need to add the missing parameters the function needs:
Code: ags

function gGUIName_Click(GUI *theGui, MouseButton button) {
  // ...
}

(And make sure the name is exactly the same as the one in the GUIs 'On click' property, which it looks like it is.)

That'll get it working, at least until the bigger problem can be sorted...

EDIT:
By the way, what version are you using? This is based on 2.72. (But oddly the 'break' seems to have happened since I also started using the latest 2.8/3.0 betas - at least, I haven't noticed it before now.)
I know what you're thinking ... Don't think that.

rich

So, you're telling me that it didn't autogenerate the function in the script may be a bug of some kind? If no one noticed it until now, I suppose it's not a very often used feature. I only needed it because I have more than one GUI on at a time, and I wanted to be able to click one and bring it to the front in the ZOrder.

Well, I went ahead and added the two parameters in there like you said and it works now. I could see why I might want to know what button was pushed on the mouse, but I don't see why I'd need GUI *theGUI. It should already by obvious given the function name and all. From there, I prefer to manipulate things with gGUIname where GUIname is the name of the GUI. Oh well.

Just so you know, I am using 2.72 here. I'm still not quite ready yet to make the switch-over to 3.0 but it does look like it has some really cool new features and tools so, I'm sure it's just a matter of time. I want to make sure all the bugs are ironed out first.
I'm so excited!

Pumaman

This could be a bug in the 2.72 editor, but it's not something I'm going to investigate because of the impending arrival of 3.0.

Khris

Just for the record, I tested this using build 2.72.652 and both double-clicking "On click" and the GUI itself worked just fine. Either the little box popped up where I could enter the function's name or I was taken to the function in the global script (if it already existed).

Plus, having the clicked GUI provided as a parameter does make sense.
Imagine a function that, say, will bring the GUI to the front by altering its Z-order.

I'd use one function, enter its name in every GUI's "On click" field and then bring theGui to the front. :o

Ashen

Just to expand a little, I was using 'On click' functions about a month ago, and they worked fine. Last week I downloaded 2.8b11 and then 3.0b12 (as it came out about 3 days later). Now, the' On click' function on the GUI Properties window doesn't work - I can set a function name, but it won't open the script. Double clicking the GUI will open the script, and create the function if necessary (didn't think to check that yesterday). I don't know if, or even how, installing the betas would affect 2.72, just mentioning it as the most significant system change I can think off. (I haven't tried opening any of my 2.72 games in the beta, and I'm using 2.72.652 too.)

And I agree that passing the clicked GUI into the function makes sense, as you might want to use the same function for multiple GUIs. Same way it works for all (I think) GUI Controls. (Which also don't seem to be accessing the script through 'On click' any more... I usually double click the Control for that, so I hadn't noticed that, either.)
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk