Author Topic: Custom Tokens  (Read 407 times)

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Custom Tokens
« on: June 03, 2011, 06:24:27 pm »


               Does it hurt to have loads of custom tokens? (1000+)
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Custom Tokens
« Reply #1 on: June 03, 2011, 07:55:30 pm »


               Well, I might just as well ask here... Any idea why this script doesn't even seem to launch?

OnModuleLoad
#include "mod_color"
void main()
{
    string sDesc = "";                 //
    GiveGoldToCreature(GetFirstPC(), 1); // //
    int r=0,g=0,b=0;
    while (r+g+b != 27)
    {
        sDesc += ColorString("XXXXXX\\n", r*25+30, g*25+30, b*25+30, 1);  //
        SetCustomToken(6000 + r*100 + g*10 + b*1, ColorString("", r*25+30, g*25+30, b*25+30));
             if ((g == 9) && (b == 9)) {r++; g=0; b=0;}
        else if             ((b == 9)) {     g++; b=0;}
        else                           {          b++;}
    }
    GiveGoldToCreature(GetFirstPC(), 2); // //
    SetCustomToken(7000, "</c>");
    SetDescription(GetObjectByTag("thechest"), sDesc);    //
}

mod_color
const string COLORTOKEN = "                  ##################$%&'()*+,-./0123456789:;;==?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[[]^_`abcdefghijklmnopqrstuvwxyz{|}~~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ¡¡¢£¤¥¦§¨©ª«¬¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþþ";

// returns a properly color-coded sText string based on specified RGB values
// ends color mode after sText if iEnd = 1
string ColorString(string sText, int nRed=255, int nGreen=255, int nBlue=255, int iEnd = 0);
string ColorString(string sText, int nRed=255, int nGreen=255, int nBlue=255, int iEnd = 0)
{
    string sEnd = "";
    if (iEnd = 1) {sEnd = "</c>";}
    return "<c" + GetSubString(COLORTOKEN, nRed, 1) + GetSubString(COLORTOKEN, nGreen, 1) + GetSubString(COLORTOKEN, nBlue, 1) + ">" + sText + sEnd;
}

Im not getting the 1 or 2 gold I put in the script for testing.
               
               

               


                     Modifié par Xardex, 03 juin 2011 - 06:59 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Custom Tokens
« Reply #2 on: June 03, 2011, 09:35:34 pm »


               GetFirstPC won't return valid on modload - there are no pcs.

Funky
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Custom Tokens
« Reply #3 on: June 04, 2011, 05:38:45 am »


               

FunkySwerve wrote...

GetFirstPC won't return OBJECT_INVALID on modload - there are no pcs.

Funky


fixed..   =D
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Custom Tokens
« Reply #4 on: June 04, 2011, 05:51:32 am »


               

FunkySwerve wrote...

GetFirstPC won't return valid on modload - there are no pcs.

Funky



_Guile wrote...

FunkySwerve wrote...

GetFirstPC won't return OBJECT_INVALID on modload - there are no pcs.

Funky


fixed..   =D



I do not know what you think you fixed _Guile.  Funky's ststment is correct.  GetFirstPC will not  return valid object on mod load.  

Your fix of his statment is 100% incorrect.  Since it will return OBJECT_INVALID every time in the on mod load event.     
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Custom Tokens
« Reply #5 on: June 04, 2011, 09:12:12 pm »


               Okay, that explains that.... But after meddling with the script some more, this breaks due to too many instructions.

To make it easier to grasp ill explain what it is supposed to do...
Basically go through 1000 colors, set tokens 6000-6999, so custom token 6900 would be brightred, 6040 dark green... (6RGB)

void SetColors()
{
    string sDesc = "";                 //
    int r=0,g=0,b=0,n=0;
    while (n != 1000)
    {
        sDesc += ColorString("XXXXXX\\n", r*25+30, g*25+30, b*25+30, 1);  //
        SetCustomToken(6000 + r*100 + g*10 + b*1, ColorString("", r*25+30, g*25+30, b*25+30));
             if ((g == 9) && (b == 9)) {r++; g=0; b=0;}
        else if             ((b == 9)) {     g++; b=0;}
        else                           {          b++;}
        n++;
    }
    SetCustomToken(7000, "</c>");
    SetDescription(GetObjectByTag("thechest"), sDesc);    //
}

Color string is the same as above... Cant figure it out.
Also about the performance of having lots of custom tokens..?
               
               

               


                     Modifié par Xardex, 04 juin 2011 - 08:14 .
                     
                  


            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Custom Tokens
« Reply #6 on: June 04, 2011, 09:20:16 pm »


               .... 1000 loops through that script causes "too many instructions"??
n++ -> n+=10
and it works. Too bad its not enough...

1000 loops? seriously?
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Custom Tokens
« Reply #7 on: June 04, 2011, 09:35:42 pm »


               Well, I got it to work and it seems it does lag. Alot.

So I reduced the amount of color intensities to 3 per color, which makes a total of 27 colors. And what is this? Exactly same amount of lag.

Switched back to 1000 varieties AND NO LAG?

What the hell?
but this is just ... IMPOSSIBLE!

It seems that it randomly lags like there is no tomorrow, or not at all.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Custom Tokens
« Reply #8 on: June 04, 2011, 09:52:54 pm »


               Why not just use.

// FILE: x3_inc_string      FUNCTION: StringToRGBString()
//
// This function will make sString be the specified color
// as specified in sRGB.  RGB is the Red, Green, and Blue
// components of the color.  Each color can have a value from
// 0 to 7.
// Ex: red   == "700"
//     green == "070"
//     blue  == "007"
//     white == "777"
//     black == "000"
// The STRING_COLOR_* constants may be used for sRGB.
string StringToRGBString(string sString, string sRGB);
 


Or is there a perpose here that I am missing. 

As far as setting the tokens I do not see a performance problem with setting them one time on ModLoad. 

The To Many Instructions error does not really care about how many loops there are in the script.  It is how many instructions are executed.  The limit is around 16000 if what I havew heard is right.  But then again I do not know if that is machine instructions or number of  instructions being fed to the script interperter.  Or where the blocking for the count is.   

I just do not know what you need to set all the tokens for that the above function will not handle.  
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Custom Tokens
« Reply #9 on: June 04, 2011, 10:19:09 pm »


               Alrighty, after lots of script honing and chilling off (sorry for my earlier almost-rage)...

The script works now, and it does actually lag if I set 1000 tokens. (Not just momentarily, it persists)
Im going with the 27 colors, it doesn't lag at all and the reason it lagged earlier was propably because I forgot to compile my stuff.

I might have used that nwn's own thingy but I didn't even know it existed. Anyhow, im good with the one I got from... somewhere... + It offers a wider spectrum of colors.

Thanks though, you are most helpful as usual. 'B)'
               
               

               


                     Modifié par Xardex, 04 juin 2011 - 09:19 .