Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Needing to call the function twice (https://forums.graalonline.com/forums/showthread.php?t=83288)

Codein 12-22-2008 07:59 PM

Needing to call the function twice
 
What this script is meant to do is:

Show the characters the player currently has, and if there's an empty character slot, display Empty Character.

The problem is, I have to update the NPC or call showGUI() twice for changes to be made. For example, if I create a character and go back to the this GUI, it doesn't update the information until I call showGUI again.

Another example: I have to click the "Delete" button twice to show the changes.

I'm not very good with explanations, so it might be a little hard to understand.


PHP Code:

function onActionServerside() {
  if (
params[0] == "getStats") {
    for (
03i++) {
      
temp.info = new TStaticVar();
      
temp.info.loadvars("mud/characters/" params[1] @ "_" i);
      
      
temp.(@ "character_" i) = temp.info.savevarstoarray(0);
    }
    
    
findPlayer(params[1]).triggerclient("gui"name"returnStats"temp.character_0temp.character_1temp.character_2);
  }
  
  elseif (
params[0] == "delete") {
    (
"-SystemCharacter").deleteChar(player.accountparams[1]);
  }
}

//#CLIENTSIDE

function onActionClientside() {
  if (
params[0] == "returnStats") {
    
    for (
03i++) {
      (
"character" i).destroy();
      
this.(@ "character_" i) = new TStaticVar(@ "character" i);
      (
"character" i).loadvarsfromarray(params[1]);
      
    }
    
  }  
}

function 
onPlayerChats() {
  if (
player.chat=="/selectchar") {
    
showGUI();
  }
}

function 
onCreated() {
  
guiCharacterSelect.destroy();
  
triggerserver("gui"this.name"getStats"player.account);
}

public function 
showGUI() {
  if (
guiCharacterSelect != NULLguiCharacterSelect.destroy();

  
triggerserver("gui"this.name"getStats"player.account);
 
  new 
GuiControlProfile("guiTextProfile") {
    
this.fontcolor = {000};
    
this.fontsize 20;
    
this.fontstyle "bc";
  } 
 
  new 
GuiWindowCtrl("guiCharacterSelect") {
    
    
destroyonhide true;
    
    
this.width 420;
    
this.height 200;
    
    
canresize false;
    
canmaximize false;
    
canminimize false;    
    
canclose false;
    
    
this.= (screenwidth 2) - (this.width 2);
    
this.= (screenheight 2) - (this.height 2);
    
    
temp.distance 120;
    
    for (
03i++) {
      
      if ((
"character" i).firstname != NULL) {
        new 
GuiTextCtrl("guiCharacterSelect_nametext" i) {
          
this.70 + (temp.distance);
          
this.= -10;
          
          
this.useownprofile true;
          
this.profile "guiTextProfile";
          
          
this.width 120;
          
this.height 100;
          
          
this.text "Slot" SPC i 1;
        }
        
        new 
GuiShowImgCtrl("guiCharacterSelect_charimg" i) {
          
this.70 + (temp.distance);
          
this.50;
          
          
this.width 100;
          
this.height 100;
          
          
this.ani "idle";
        }
        
        new 
GuiButtonCtrl("guiCharacterSelect_buttonload" i) {
          
this.45 + (temp.distance);
          
this.98;
          
          
this.width 100;
          
this.height 20;
          
          
this.text "Load";
          
          
//thiso.catchevent(
        
}
        
        new 
GuiButtonCtrl("guiCharacterSelect_buttondelete" i) {
          
this.45 + (temp.distance);
          
this.128;
          
          
this.width 100;
          
this.height 20;
          
          
this.text "Delete"
          
          
this.slot i;
          
          
thiso.catchevent(name"onAction""onDeleteChar");         
        }
        
      }
      
      else {
        new 
GuiTextCtrl("guiCharacterSelect_emptytext" i) {
          
this.45 + (temp.distance);
          
this.= -10;
          
this.width 100;
          
this.height 100;
          
          
this.text "Empty Slot";
          
          
this.useownprofile true;
          
this.profile "guiTextProfile";
        }
        
        new 
GuiButtonCtrl("guiCharacterSelect_buttoncreate" i) {
          
this.40 + (temp.distance);
          
this.60;
          
          
this.width 100;
          
this.height 20;
          
          
this.slot i;
          
          
this.text "Create";
          
          
thiso.catchevent(name"onAction""onCreateChar");
          
        }
        
      }
      
    }
  }
}

function 
onDeleteChar(objmodmousexmouseyclickcount) {
    
triggerserver("gui"this.name"delete"obj.slot);
    
showGUI();
}

function 
onCreateChar(objmodmousexmouseyclickcount) {
    (
"-GUICharacterCreation").showGUI(obj.slot);
    
guiCharacterSelect.destroy();



Codein 12-22-2008 08:15 PM

I fixed it, by placing a sleep() after the triggerserver() in the showGUI() function. I think the problem was that the triggers didn't have enough time to grab the data I needed before the GUI was drawn.

cbk1994 12-23-2008 05:14 AM

Yes, that was the problem.


All times are GMT +2. The time now is 10:07 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.