Graal Forums

Graal Forums (http://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (http://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Guide: Naming GUI Controls (http://forums.graalonline.com/forums/showthread.php?t=85600)

cbk1994 05-16-2009 11:39 PM

Guide: Naming GUI Controls
 
I've seen a lot of people doing this lately, and I wanted to let them know that it should be done differently in nearly all cases.

Rather than naming your GUI windows (and other controls) such as

Graal Script Code:

new GuiWindowCtrl("Window") {
  
// whatever


put part of the thing you're creating it in

Graal Script Code:

new GuiWindowCtrl("JailInformation_Window") {
 
// whatever


The reason this matters is because if you name your buttons things like "Button1" and "Close", which I've seen a lot of people doing, any script that has

Graal Script Code:

function Button1.onAction() {
  
triggerserver("gui"name"summonAllPlayers");


or any other function having to do with that button would be called, not just the script that created it.

Lesson's over, thanks for reading.

Tigairius 05-16-2009 11:41 PM

Stickied.

fowlplay4 05-17-2009 07:00 PM

I normally name the GuiWindowCtrl's or GuiBitmapBorderCtrl's after the main title for it.

I.e: JailInformation instead of JailInformation_Window

But everything below that uses your naming convention.

I.e Close button: JailInformation_Close

Chompy 05-17-2009 07:12 PM

Personal preference.

xXziroXx 05-17-2009 10:52 PM

Quote:

Originally Posted by Chompy (Post 1492002)
Personal preference.

I disagree, more like coding standard.

cbk1994 05-17-2009 11:12 PM

Quote:

Originally Posted by fowlplay4 (Post 1491998)
I normally name the GuiWindowCtrl's or GuiBitmapBorderCtrl's after the main title for it.

I.e: JailInformation instead of JailInformation_Window

But everything below that uses your naming convention.

I.e Close button: JailInformation_Close

The reason I would add the _Window is so I can, for example, close all those windows.

Graal Script Code:

for (temp.control GraalControl.controls) {
  if (
control.name.starts("JailInformation_")) {
    
control.destroy();
  }


without picking up JailInformation2_Window or whatever for a completely different window.

I see what you mean, though.
Quote:

Originally Posted by Chompy (Post 1492002)
Personal preference.

It's not really personal preference. If you name all your windows "Window", you're going to have problems.

Skyld 05-18-2009 01:00 AM

Quote:

Originally Posted by Chompy (Post 1492002)
Personal preference.

Actually, it is completely common sense. If we all had scripts using generic GUI object names like "Window", then everyone's scripts would break everyone else's scripts. At least having the name of the script or something means that the chance of collision is much less likely.

It's actually quite funny how many times I came across this when I was a GST; people's scripts not working because they did the exact same thing and used generic object names, only to later find that the same object name had been used elsewhere and that they were going to conflict.

LoneAngelIbesu 05-20-2009 11:02 PM

Quote:

Originally Posted by Chompy (Post 1492002)
Personal preference.

I believe Chompy is referring to this:
Quote:

Originally Posted by fowlplay4 (Post 1491998)
I normally name the GuiWindowCtrl's or GuiBitmapBorderCtrl's after the main title for it.

I.e: JailInformation instead of JailInformation_Window

But everything below that uses your naming convention.

I.e Close button: JailInformation_Close

... not to using descriptive names.

Chompy 05-20-2009 11:09 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1492678)
I believe Chompy is referring to this:


... not to using descriptive names.

Indeed, forgot to quote Jerret. D:
Sorry.

fowlplay4 11-23-2011 03:53 AM

Quote:

Originally Posted by khortez (Post 1675109)
Why am I naming my Gui's anything?

So your GUI has an ID that you can use to manipulate/debug it in your code. Properly labeled code is also much more readable.

Labeled incorrectly you would not know which button is the close or open button:

MyForm_Button_1
MyForm_Button_2

Labeled and used correctly you have a much better idea:

MyForm_Button_Open
MyForm_Button_Close

This can be applied to many other object types or GUIs.

khortez 11-23-2011 04:00 AM

Quote:

Originally Posted by fowlplay4 (Post 1675122)
So your GUI has an ID that you can use to manipulate/debug it in your code. Properly labeled code is also much more readable.

Labeled incorrectly you would not know which button is the close or open button:

MyForm_Button_1
MyForm_Button_2

Labeled and used correctly you have a much better idea:

MyForm_Button_Open
MyForm_Button_Close

This can be applied to many other object types or GUIs.

thanks, now how would i make a custom profile?

fowlplay4 11-23-2011 04:33 AM

Quote:

Originally Posted by khortez (Post 1675124)
thanks, now how would i make a custom profile?

Search the forums and the wiki next time:
http://wiki.graal.net/index.php/Crea...g_GUI_Profiles

khortez 11-23-2011 04:51 AM

I have, even seen that link you gave me just now. But there is always a possibility I misinterpreted what i've read.



Edit: If there was anyone that can say they have searched everywhere or at least thoroughly for answers, it'd be me.


All times are GMT +2. The time now is 08:04 AM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.