Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   GUI textlist problem. (https://forums.graalonline.com/forums/showthread.php?t=85350)

Jiroxys7 04-28-2009 01:51 AM

GUI textlist problem.
 
I'm a bit new to GS2, but i managed to make a GUI that pops up, gives the player a list of options, which the player clicks, then clicks the button that applies the selection and closes the window.

Inside the script telling the apply button to check what was selected, i basically use the following setup:
if(){}
else if () {}
else if () {}
else if () {}
etc.

however, it seems that no matter what i select, it always chooses whatever the last if(){} on the list was.

for examle If the setup is the following:
if(){}//line 1
if(){}//line 2
if(){}//line 3
if(){}//line 4

then whatever i select will be whatever is on line 4.

HOWEVER, if the setup is like this:
if(){}//line 1
else if(){}//line 2
else if(){}//line 3
else if(){}//line 4

then no matter what option is chosen, the NPC will always use whatever is on line 1.

has the "else" feature changed in GS2 or something?

EDIT: Maybe "GUI textlist problem" was the wrong name to call the thread, but any help would still be greatly appreciated.

salesman 04-28-2009 01:56 AM

Post the code that you're having the problem with?

Gambet 04-28-2009 01:59 AM

No, the "else feature" works the same as it always has, which is exactly as it should work.

PHP Code:

//#CLIENTSIDE
function onCreated()
{
 
temp.foo "bar";

 if (
foo == "apple")
  
player.chat "Apple!";
 else if (
foo == "bar")
  
player.chat "FooBar!";
 else
  
player.chat "Whatever";



^The above would set your chat to "FooBar!"

Jiroxys7 04-28-2009 02:30 AM

on another glance, it might actually be that it may not be checking/setting strings the same way?

heres the area i'm having trouble with:

PHP Code:

function MyclassGUI_Button1.onAction() {
  if(
this.selectedprofession=profession1){
  
setstring client.playerprofession,profession1;
  
MyclassGUI_Window1.destroy();
  }
  else if(
this.selectedprofession=profession2){
  
setstring client.playerprofession,profession2;
  
MyclassGUI_Window1.destroy();
  }
  else if(
this.selectedprofession=profession3){
  
setstring client.playerprofession,profession3;
  
MyclassGUI_Window1.destroy();  
 } 


napo_p2p 04-28-2009 02:36 AM

For comparision, you need to be using == and not =.

Also (not related to your problem), setstring is GS1 and deprecated. You should be using something like this instead:
PHP Code:

client.playerprofession profession1

And lastly, welcome to the scripting forum :).

salesman 04-28-2009 02:48 AM

Also, if profession1 and the rest are not variables, you need to use quotes because they are strings.

It might also be simpler to just forget the if statements and just do something like:

PHP Code:

function MyclassGUI_Button1.onAction() { 
  
client.playerprofession this.selectedprofession;
  
MyclassGUI_Window1.destroy();


Unless of course you're planning on adding more

Jiroxys7 04-28-2009 02:49 AM

edit: okay it got that working. i just needed a few more things in quotes.

thanks for the help guys.

but before i'm done with this thread, whats the advantage of using
PHP Code:

function MyclassGUI_Button1.onAction() { 
  
client.playerprofession this.selectedprofession;
  
MyclassGUI_Window1.destroy();


over what i have now?

edit: nvm lol

napo_p2p 04-28-2009 02:59 AM

Quote:

Originally Posted by Jiroxys7 (Post 1487303)
well that seemed to have fixed a few things, however client.playerprofession = profession1 didnt seem to save it under the player's flags. so its now set to "0" instead of "profession1" (i have another GUI thats now displaying the profession as "0")

I'm sorry, I just skimmed over the script. It should have been:
PHP Code:

client.profession "profession1"

However, salesman's suggested method is the way to go.

Just for reference, when you check or assign literal strings, you need to use quotes.
For example, the first 'if' statement should have been:
PHP Code:

if (this.selectedprofession == "profession1"


Jiroxys7 04-28-2009 03:09 AM

yep, thanks for the help guys :D


All times are GMT +2. The time now is 11:05 AM.

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