Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-28-2009, 01:51 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
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.
Reply With Quote
  #2  
Old 04-28-2009, 01:56 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Post the code that you're having the problem with?
Reply With Quote
  #3  
Old 04-28-2009, 01:59 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
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!"
Reply With Quote
  #4  
Old 04-28-2009, 02:30 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
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();  
 } 
Reply With Quote
  #5  
Old 04-28-2009, 02:36 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
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 .
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.

Last edited by napo_p2p; 04-28-2009 at 02:48 AM..
Reply With Quote
  #6  
Old 04-28-2009, 02:48 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
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
Reply With Quote
  #7  
Old 04-28-2009, 02:49 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
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

Last edited by Jiroxys7; 04-28-2009 at 03:09 AM..
Reply With Quote
  #8  
Old 04-28-2009, 02:59 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by Jiroxys7 View Post
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"
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #9  
Old 04-28-2009, 03:09 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
yep, thanks for the help guys
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:53 PM.


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