Author Topic: Arrays  (Read 2247 times)

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Arrays
« Reply #45 on: July 04, 2011, 07:49:12 pm »


               @ OP,  
I think it would be safe for you to make a new thread for your topic.  

Perhaps something without the word 'Array' in the title.

This thread has strayed far from helping you.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Arrays
« Reply #46 on: July 04, 2011, 10:44:38 pm »


               

Lightfoot8 wrote...

@ OP,  
I think it would be safe for you to make a new thread for your topic.  

Perhaps something without the word 'Array' in the title.
 

':lol:':lol:':lol:'

true btw
               
               

               
            

Legacy_Craden

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Arrays
« Reply #47 on: October 16, 2011, 02:26:14 am »


               Why not something simple like this:

//Author: myb7721@gmail.com

void createArray(string sName, int iSize, object oObject){

    int i;
    for(i = 0; i < iSize; i++){
        SetLocalString(oObject, sName + i, "");
    }

}

void arraySetIndex(string sArrayName, int iIndex, string sString, object oObject){
      SetLocalString(oObject, sName + iIndex, sString);
}

string arrayStringAt(string sArrayName, int iIndex, object oObject){
     return GetLocalString(oObject, sName + iIndex, "");
}
               
               

               


                     Modifié par Craden, 16 octobre 2011 - 01:31 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Arrays
« Reply #48 on: October 16, 2011, 03:11:39 am »


               

Craden wrote...

Why not something simple like this:

//Author: myb7721@gmail.com

void createArray(string sName, int iSize, object oObject){

    int i;
    for(i = 0; i < iSize; i++){
        SetLocalString(oObject, sName + i, "");
    }

}

void arraySetIndex(string sArrayName, int iIndex, string sString, object oObject){
      SetLocalString(oObject, sName + iIndex, sString);
}

string arrayStringAt(string sArrayName, int iIndex, object oObject){
     return GetLocalString(oObject, sName + iIndex, "");
}





Yes that would work, But I still to nit pick one thing.  in your createArray function you use:
SetLocalString(oObject, sName + i, "");
this is pointless, the more locals you have on an object the longer it takes to find the one you need.  So there is no reason to have a bunch of lables with null values on the object. it would have been much better to use:
DeleteLocalString(oObject, sName + i);
if you wanted to make sure that they where all null. 

It was also noted somewhere in the mess above that the method you are useing is already in the "nw_o0_itemmaker" #include. with the functions SetLocalArrayString and SetLocalArrayInt.

So yes your method works.   Some of us however like to complicate things to our own liking.

L8
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Arrays
« Reply #49 on: October 16, 2011, 05:15:19 pm »


               <tossing another...>

Lightfoot8 wrote...
...
It was also noted somewhere in the mess above that the method you are useing is already in the "nw_o0_itemmaker" #include. with the functions SetLocalArrayString and SetLocalArrayInt.

So yes your method works.   Some of us however like to complicate things to our own liking.
L8

Do you have any idea how much I cried <ranted, screamed, pleaded...> when Don told us we wouldn't have arrays? Almost as loud as when we learned we weren't getting a socket for 3rd party apps.

How much skull sweat we put into work-arounds that were *all* moot?!

Didn't really understand why until I read Skywing's analysis of the NwScript interpreter.
No registers. All stack. Fixed cells. Two pointers. Second pointer stored *on the stack*.

Pseudo-arrays (have you looked at the way they work? Ack.) jump through hoops to pretend to be arrays which we are familiar with (well, *I* am).

From the Lexicon
Although this is hardly an array, it can be accessed like one, and can even be looped through. It works by creating a new local integer object on whatever object you passed in through the parameters. This LocalInt is called sVarName + nVarNum, so in otherwords if I called the following: 

GetLocalArrayInt(OBJECT_SELF, "MyArray", 1); 

meaning I want the value in position one of MyArray on OBJECT_SELF. It would call GetLocalInt(OBJECT_SELF, "MyArray1") to retrieve the value. So if you create one array and have 300 values stored in it, you've actually created 300 variables with values on the object. This just hides the mess for you.

You don't do much better with linked lists.

Not trying to start a new flame, but seriously advise people to code in a way that works for them, while keeping in mind that, working solely with a stack, every time you do something different with a different value, you are incurring overhead with stack management.  <clear as mud, boss> Grrr. How about "Keep is simple, silly"? <not very helpful> Heh.

How about this, then: Read the Grey Fox' post. Twice. Then go ahead and write script that works, whatever speed. Then tweak it. Ask advice. *Take* advice.
[edit: gray.fox, not grey... :-P Too much java! '=]'

We are working with a creaking, ancient engine (Deity, how I love her!) and creating things *because we want to*. If someone laughs at you... Hey!, You got 'em to laugh! =)
Meanwhile, just keep impressing your personality on the NwN-sphere.

<...hanky in the laundry basket>
               
               

               


                     Modifié par Rolo Kipp, 16 octobre 2011 - 08:23 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Arrays
« Reply #50 on: October 18, 2011, 07:09:18 am »


               Wow at the necroposting. '<img'> The OP wound up pm'ing me for advice months ago.

Funky
               
               

               
            

Legacy_Guest_EternalAmbiguity_*

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Arrays
« Reply #51 on: October 18, 2011, 07:13:32 am »


                I know, right?
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Arrays
« Reply #52 on: October 18, 2011, 04:08:02 pm »


               <poking IT...>

FunkySwerve wrote...
Wow at the necroposting. '<img'> The OP wound up pm'ing me for advice months ago.

But is a topic really dead if people are still asking questions? ;-)

Glad you could help TrekSL, though. You help me often enough :-)

Maybe you could add a tutorial on arrays, pseudo arrays and alternatives to the Lexicon... Your de-lag tutorial was great!

<...with a stick>
               
               

               


                     Modifié par Rolo Kipp, 18 octobre 2011 - 03:10 .