OnClick functions for renamed buttons in 3.0 [SOLVED]

Started by paolo, Thu 28/02/2008 07:29:10

Previous topic - Next topic

paolo

I'm having fun adapting to 3.0. It's very nice, guys, and a great improvement over 2.7x.

I have a problem with the OnClick function for a button. In 2.7x, when you opted to run the global script on clicking on a button, AGS wrote the function stub for you. In 3.0, you have to do this yourself. Fair enough, but this is where I am running into difficulties.

The button was initially called Button1, and so I wrote

Code: ags

function Button1_OnClick(GUIControl *control, MouseButton button)
{
	//my code here
}


This worked fine. Then I decided to give my button a more meaningful name and changed the Name field of the button to GameActionsButton. I updated my code accordingly:

Code: ags

function GameActionsButton_OnClick(GUIControl *control, MouseButton button)


Now nothing happens when I click on the button. If I restore the old function name, it works again. Does this mean that once you write an OnClick function for a button, that name is set in stone, or that you can't rename buttons, or that you mustn't rename buttons after you've written OnClick functions for them? Surely AGS 3.0 isn't so restrictive. What am I doing wrong here?

Thanks.

EDIT: Ah, I've found what I need to be doing - I should be clicking on the lightning bolt above the attributes panel to generate the function stub in the code.

However, the function is still Button1_OnClick - why does it not update to the new name?

Gilbert

I think you can use whatever name for the function you want, just click the lightning button (events) in the GUI's property pane and fix the function name on the right of "OnClick", I think when you first add that function without touching the events button it memorised the function name there, so if you want to change just change it in the events option.

paolo

OK, I see what I have to do...

* Click on the lightning bolt
* Delete the name already against "OnClick"
* Click the ... button

The new function name then appears in the panel and in the script.

That's great - thanks for your help.

SMF spam blocked by CleanTalk