logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Terrible discovery
Goto page Previous  1, 2
 
Post new topic   Reply to topic    nwnx.org Forum Index -> General Discussion
View previous topic :: View next topic  
Author Message
Xildjian



Joined: 08 Jan 2005
Posts: 100

PostPosted: Sat Feb 26, 2005 1:53    Post subject: Reply with quote

dguntner wrote:
Question: Will switch/case sets work with strings, or are they all numeric? I.E., will something like


switch (variable)

case "somestring"
{blah}


The argument for a switch statement needs to be an interger value. The only exception to this is a single character because the compiler can get an ASCII equivelent integer value. So, you can technically do this:

switch(variable)
case 'a' {}
case 'b' {}
case 'c' {}

However if bioware decided to implement it correctly like this is another matter.
_________________
Member Shadow of Iniquity development team
Back to top
View user's profile Send private message
Xildjian



Joined: 08 Jan 2005
Posts: 100

PostPosted: Sat Feb 26, 2005 1:58    Post subject: Reply with quote

dguntner wrote:
Grinning Fool wrote:
Someting you may want to consider, if readability is the concern, is this:
Code:

const int MONSTER_BUGBEAR = 1;
const int MONSTER_ORC = 2;
const int MONSTER_WYRM = 3;

....

switch (nMonster) {
    case MONSTER_BUGBEAR:
         ...
         break;
    case MONSTER_BUGBEAR:
         ...
         break;
    case MONSTER_WYRM:
         ...
         break;
     default:
         ...
         break;
}           


Hey, I *like* that. I hope Lanther can be persuaded to do it that way. Smile

--Dave


This brings up the question if nwn script supports enumeration. Example:
enum {
TEST =1,
NEXT,
LAST
}
where
TEST =1
NEXT = 2
LAST 3
The compiler would do this mapping for you. Also, you could assign TEST = 10 and the nect values would be NEXT = 11, and LAST = 12.
_________________
Member Shadow of Iniquity development team
Back to top
View user's profile Send private message
dougnoel



Joined: 21 Mar 2005
Posts: 27
Location: VA

PostPosted: Mon Mar 21, 2005 18:34    Post subject: Reply with quote

dguntner wrote:
NoMercy wrote:

... One thing came to mind, what's Torlack's NSS compilers preformance on switch() statements?


That's a really good question. Hadn't even thought of that. Torlack hasn't updated in ages, so it doesn't work with SoU/HotU, but the PRC group took it over and released the compiler. I use that compiler for my module (I never bother with Build/Compile Scripts in the toolset anymore.

I can't try Lanthar's test with the two scripts that he used because no one has ported the profiler plugin to Linux. Lanthar, have you tried using the PRC compiler on your test module to see what happens when you run those two scripts? It's at:

http://nwvault.ign.com/Files/other/data/1098057351000.shtml

in case you don't currently use it and want to try it out. Any chance you could be persuaded to give it a shot? It'd be interesting to see if they handle switch/case differently than Bioware did....

--Dave

I know this thread's a month old, but I was wondering if anyone had an answer to this question? I'm working on spellhooking over at Avlis and I chose to use a switch statement for the reasons outlined by Lanthar. We've got 147 cases now and we're starting to have some lag issues. It's unclear if it's the case statement, but Pap pointed me to this thread and I figure it's worth investigating. We're probably less than halfway there. Before I read this I was wondering if the PrC compiler did anything with switch statements and then I saw the same question asked here. Anyway, thought I'd ask.

Thanks,
Doug
Back to top
View user's profile Send private message Send e-mail
Lanthar D'Alton



Joined: 10 Feb 2005
Posts: 100

PostPosted: Tue Mar 22, 2005 9:35    Post subject: That is a good question. Reply with quote

Unfortunately, my laptop with all that is currently feeling a little under the weather while I await the arrival of a replacement vid. card...

http://lanthar.dyndsl.com/i/laptop_in_pieces.jpg

-Lanthar
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
dguntner



Joined: 31 Dec 2004
Posts: 116

PostPosted: Tue Mar 22, 2005 21:17    Post subject: Reply with quote

Well, that other computer doesn't look like it's in pieces. Use that. Very Happy

--Dave
Back to top
View user's profile Send private message
rdjparadis



Joined: 01 Apr 2005
Posts: 2

PostPosted: Fri Apr 01, 2005 11:09    Post subject: Reply with quote

Try this code for spellhooking, the more spells you override, the more efficient this is compared to the switch/case and the if/else.


(Your spell override script)
Code:
 void main()
{
  ExecuteScript(GetLocalString(GetModule(),"SPELL" + IntToString(nSpell)),OBJECT_SELF);
}


Then add this as a function, or a separate script run in the OnModuleLoad event. Copy and paste the SetLocalString line with the new spell constant and name of the script for the new spell.
Code:
    object module = GetModule();
    string spell = "SPELL";

    SetLocalString(module, spell + IntToString(SPELL_ETHEREALNESS),"spether");


This will results in more smaller scripts for your module, but less instructions each time a spell is cast. It can also be easily converted to use database stores script names instead of local string stored script names, but local variables are quicker access.
Back to top
View user's profile Send private message MSN Messenger
rdjparadis



Joined: 01 Apr 2005
Posts: 2

PostPosted: Fri Apr 01, 2005 11:22    Post subject: Reply with quote

I missed a line in the spell override script there
Code:
 void main()
{
  int nSpell=GetSpellId();
  ExecuteScript(GetLocalString(GetModule(),"SPELL" + IntToString(nSpell)),OBJECT_SELF);
}
Back to top
View user's profile Send private message MSN Messenger
Lanthar D'Alton



Joined: 10 Feb 2005
Posts: 100

PostPosted: Tue Apr 05, 2005 19:14    Post subject: Okay, back in one piece Reply with quote

I've fixed my laptop... and just grabbed that compiler... I'll let you know soon.

On another note, the switch tmi'd faster than I could blink, so I doubt your 147 case statement is really the cause of your lag.

If I were you, I'd check for the worst lag culprit I've found. Go to any store and sell the vendor over 175 "miscellaneous small" items. After filling 5 pages, you will notice a huge lag hit for EVERY item you buy from him from then on... I'm talking 4 seconds at 100% cpu... It was beating my module to a pulp when people started selling their cnr gem dust to merchants to get 1 gold each instead of tossing them.

-Lanthar
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
dguntner



Joined: 31 Dec 2004
Posts: 116

PostPosted: Tue Apr 05, 2005 19:23    Post subject: Reply with quote

That's why you put a script in the merchant OnClosed that deletes anything that was sold to it by a PC. Very Happy

--Dave
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> General Discussion All times are GMT + 2 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group