Interface_click problem (SOLVED)

Started by Protostar, Fri 13/07/2007 13:24:21

Previous topic - Next topic

Protostar

I've made a gui button, set run_script interaction called Actions_Click and told it to open new gui on click. The new gui exists, all is clickable, but first I couldn't get any interaction. So I did a little tinkering and now after clicking game crashes, saying:

Error: run_text_script1: error -1 running function 'interface_click':
Runtime error: wrong number of parameters to exported function 'interface_click' (expected 0, supplied 2)

Here's part of my interface_click script (along with one working button, so you know I can do things right):

Code: ags
#sectionstart interface_click  // DO NOT EDIT OR REMOVE THIS LINE
function interface_click() { //no parameters because it wasn't reading default ones (yes, 
                                  // I did delete the whole interface_click manually at some point :( )
}
#sectionend interface_click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart Start_Click  // DO NOT EDIT OR REMOVE THIS LINE //working button
function Start_Click(GUIControl *control, MouseButton button) { 
character[COLBERT].SetAsPlayer();
gInterface.Visible=true; //opens interface gui
gText.Visible=false; //closes menu gui
StopMusic();
}
#sectionend Start_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart Actions_Click  // DO NOT EDIT OR REMOVE THIS LINE //here's the unworking button
function Actions_click(GUIControl *control, MouseButton button) { //opening interactions window
gBody.Visible=true; //opens gui Body
}
#sectionend Actions_Click  // DO NOT EDIT OR REMOVE THIS LINE



This is pretty important because my whole interface idea depends on it. I'm pretty stuck. Help, please.

GarageGothic

#1
As I see it, the problem is that you deleted the interface_click function. I don't quite understand the comment about it not reading the default parameters. But obviously the crash is due to the game running interface_click(int interface, int button) while the current format of the function is interface_click(). Have you tried putting those parameters back in

Either way, interface_click is now pretty much obsolete for most uses, due to the script to run being selected directly in the GUI editor. So I'm wondering if you have actually specified a script to run for the button, or just set Left click to "Run Script" without specifying a script for the Click?

Gilbert

interface_click() is actually not obsolete, it is VERY important if you manage the order of the interfaces/buttons well, and check for stuff with a loop.

GarageGothic

#3
It's obsolete as the easiest way of running scripts for a button click (mainly because script-o-names means that we don't have to keep track of the numbers of every GUI and GUI object). In fact I just realized that I don't have a single interface_click script in my otherwise GUI heavy game.

Edit: In response to what Gilbot writes below, I just find that a single interface_click as opposed to individual functions turns into endless rows of nested "if" and "else if"s, becoming increasingly hard to troubleshoot. Also the fact that script-o-names appear in the autocomplete menu is great for disorganized people like me.

Gilbert

Unless you're fond of the OO way of namely everything, even when it's unnecessary.
It actually saves time and produce much more readible codes if you need to do something (just mucked up codes) like this:
Code: ags

function interface_click(int interface, int button) {
  if (interface==5) {
      ii=0;
      while (ii<5){
         if (button==ii) saveddata += ii;
         ii++;
      }
   }
}


There're advantages using OO style scripting and lot's of separate functions, but it's not always the case as in some circumstances they're not very handy.

Anyway, it's NEVER a good practice to remove any of the engine-internally-supported functions from the global script, doing so will just cause troubles, if you don't use it, just leave it there.

Protostar

Thanks for quick replies. I did the mistake of writing the thing manually instead using GUI Edit Script function. Works like a charm now.

As to deleting, at some point I clicked Edit script a few times too much and ended with more than one interface_click section in the script, thus I deleted them, but forgot to keep one.

monkey0506

#6
interface_click can be useful as a sorting function if needed though. And you can use the script o-names to make the function more readable as well. For example if I have buttons named btnUse, btnTalk, and btnLook I can write my interface_click function like this:

Code: ags
function interface_click(int guiID, int controlID) {
  if (guiID == btnUse.OwningGUI.ID) { // in case you don't know the parent GUI's name do it this way
    if (controlID == btnUse.ID) mouse.Mode = eModeUse;
    }
  else if (guiID == btnTalk.OwningGUI.ID) { // of course "else" would mean the buttons are
                                            // on different GUIs...okay, so crappy example...but you get the idea.
    if (controlID == btnTalk.ID) mouse.Mode = eModeTalk;
    }
  else if (guiID == btnLook.OwningGUI.ID) {
    if (controlID == btnLook.ID) mouse.Mode = eModeLook;
    }
  }


But Windows just downloaded updates and wants to restart and as such is insisting that Firefox keeps encountering errors and keeps closing. So...

SMF spam blocked by CleanTalk