Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1
    Banned
    Join Date
    May 2011
    Posts
    917
    Points
    1,182
         User Info     Contact     Gamer ID
    Join Date
    May 2011
    Posts
    917
    Points
    1,182

    Default [Sequel][TUT] How to script part 5

    Arrays today we are going to talk about arrays. These are more advanced because they can be hard to understand.
    1. Arrays. arrays are weird by nature. here is a array inside a script I will explain later.
    Code:
    Example()
    {
             self.array = [];
             self.array[0] = "0";
             self.array[1] = "1";
             self.array[2] = "2";
             self.array[3] = "3";
             self.array[4] = "4";
             self.array[5] = "5";
    }
    Arrays, can be used for various things. referring to scripts, Text, and other stuff. I will now explain the code.
    This is are prefix as noted in previous TUT's they can usually be ( player, level, self, or a custom one )
    This is the name and can be changed to anything, but must be the same as the start and the rest so it can be added to the array.
    This is the number that can range to anything from 0 to 100,000,000,000
    This is always used for the start so It would be like this:
    Code:
     Example()
    {
              self.YourArrayName = [];
    }
    2. Text to refer in Arrays. Here I will show how to display multiple text just with Array's and iPrintIn function. Like this:
    Code:
    Example()
    {
             self.array = [];
             self.array[0] = "0";
             self.array[1] = "1";
             self.array[2] = "2";
             self.array[3] = "3";
             self.array[4] = "4";
             self.array[5] = "5";
             for( i = 0; i <= 5; i++ )
             {
                      self thread iPrintln( "Text with Arrays." + self.array[i] );
             }
    }
    3. Functions with Arrays. Now this is easy as Pie.
    Code:
    Example()
    {
             self.array = [];
             self.array[0] = ::nothing;
             self.array[1] = ::nothing;
             self.array[2] = ::nothing;
    }
    
    init()
    {
             for( i = 0; i <= 3; i++ )
             {
                       self thread [[self.array[i]]](); //go to bottom on how this works..
             }
    }
    
    nothing()
    {
    }
    To initiate arrays, with a for statement without using a if statement you put them inside two opening and closing braces as well add 2 parentheses and a semi colon to end it. Like this: sorry for being inside the code :P
    Code:
     self thread[[self.yourArray[i]]]();
    Thats it.

    0 Not allowed! Not allowed!
    Last edited by MorderVonJuden; 06-02-2012 at 08:59 PM.

  2. #2
    Wii Coder
    ChumLee's Avatar

    Badge

    Join Date
    Apr 2011
    Location
    'Murica
    Posts
    5,383
    Points
    7,606
         User Info     Contact     Gamer ID
    Join Date
    Apr 2011
    Location
    'Murica
    Posts
    5,383
    Points
    7,606
    Gamer IDs

    Gamertag: TERR0Rx9

    Contact info:

    Youtube Channel: http://www.youtube.com/user/HAXZingTERR0R

    Default

    Nice and simple. It's pretty self explanatory after seeing this. Nice job.

    0 Not allowed! Not allowed!


  3. #3
    Banned
    Join Date
    May 2011
    Posts
    917
    Points
    1,182
         User Info     Contact     Gamer ID
    Join Date
    May 2011
    Posts
    917
    Points
    1,182

    Default

    Thank you very much. I really am trying to contribute.

    0 Not allowed! Not allowed!

  4. #4
    MonsterCat
    Insan3Lik3
    CheeseToast's Avatar
    Join Date
    Apr 2011
    Location
    Calgary, Alberta, Canada
    Posts
    4,684
    Points
    4,169
         User Info     Contact     Gamer ID
    Join Date
    Apr 2011
    Location
    Calgary, Alberta, Canada
    Posts
    4,684
    Points
    4,169

    Contact info:

    Youtube Channel: http://www.youtube.com/CheeseToastHax

    Default

    Nice work.
    But
    Example()
    {
    self = prefix;
    prefix.YourArrayName = [];
    }
    This would confuse me If I was a beginner,
    I would just do
    self.YourArrayName = [];

    for( i = 0; i <= 3; i++ )
    {
    self.array[i]; //might be a syntax error idk?
    }
    You didn't do anything with self.array,
    self thread [[self.array[i]]]();
    since your using i to go through everything,
    this would go through all the scripts with a self thread.

    Nice work.
    But
    Example()
    {
    self = prefix;
    prefix.YourArrayName = [];
    }
    This would confuse me If I was a beginner,
    I would just do
    self.YourArrayName = [];

    for( i = 0; i <= 3; i++ )
    {
    self.array[i]; //might be a syntax error idk?
    }
    You didn't do anything with self.array,
    self thread [[self.array[i]]]();
    since your using i to go through everything,
    this would go through all the scripts with a self thread.

    edit:
    player, level, self, or a custom one
    Those are all different.
    self.variable is to you
    level.variable is for the whole game
    player.variable is like self, just use on onPlayerConnected()

    0 Not allowed! Not allowed!
    "It's better to lose an argument/debate then to win. Cause when you lose you grow as a person."
    -CheeseToast

  5. #5
    Banned
    Join Date
    May 2011
    Posts
    917
    Points
    1,182
         User Info     Contact     Gamer ID
    Join Date
    May 2011
    Posts
    917
    Points
    1,182

    Default

    Quote Originally Posted by CheeseToast View Post
    Nice work.
    But

    This would confuse me If I was a beginner,
    I would just do
    self.YourArrayName = [];


    You didn't do anything with self.array,
    self thread [[self.array[i]]]();
    since your using i to go through everything,
    this would go through all the scripts with a self thread.
    Thanks, I couldn't remember how to do it thanks for posting the suggestions I will change them. and add on how this works 'self thread [[self.array[i]]]();'

    Quote Originally Posted by CheeseToast View Post
    edit:

    Those are all different.
    self.variable is to you
    level.variable is for the whole game
    player.variable is like self, just use on onPlayerConnected()
    I covered this in a earlier TUT, but thanks for letting them know.

    0 Not allowed! Not allowed!

  6. #6
    Formally known as Tlpwnzer KazzababeGamer's Avatar
    Join Date
    Jun 2011
    Posts
    2,947
    Points
    5,427
         User Info     Contact     Gamer ID
    Join Date
    Jun 2011
    Posts
    2,947
    Points
    5,427

    Default

    array = strtok("Too short|Too many threads|Combine your tuts", "|");
    for(I=0;I<array.size;I++) iPrintLnBold(array[I]);

    0 Not allowed! Not allowed!

  7. #7
    MonsterCat
    Insan3Lik3
    CheeseToast's Avatar
    Join Date
    Apr 2011
    Location
    Calgary, Alberta, Canada
    Posts
    4,684
    Points
    4,169
         User Info     Contact     Gamer ID
    Join Date
    Apr 2011
    Location
    Calgary, Alberta, Canada
    Posts
    4,684
    Points
    4,169

    Contact info:

    Youtube Channel: http://www.youtube.com/CheeseToastHax

    Default

    I still gotta learn what the
    strtok
    command means. Is it like
    setting multiple arrays in 1 line?

    Btw The custom text thing, like
    hello = "hello";
    this is just momentary variables.
    They can't be used out side of the script.

    here()
    {
    text = "hello";
    self iprintlnbold(text);
    }

    randomOtherScript()
    {
    self iprinntlnbold(text)//ERROR, The variable isn't made in the script, so it can't be used again
    }

    I always just use self. instead of these because they are the same thing but can be used outside of the script.

    0 Not allowed! Not allowed!
    "It's better to lose an argument/debate then to win. Cause when you lose you grow as a person."
    -CheeseToast

  8. #8
    Banned
    Join Date
    May 2011
    Posts
    917
    Points
    1,182
         User Info     Contact     Gamer ID
    Join Date
    May 2011
    Posts
    917
    Points
    1,182

    Default

    strok command is used in CFG modding in XML. It is also a native function and more advanced.

    0 Not allowed! Not allowed!

  9. #9
    MonsterCat
    Insan3Lik3
    CheeseToast's Avatar
    Join Date
    Apr 2011
    Location
    Calgary, Alberta, Canada
    Posts
    4,684
    Points
    4,169
         User Info     Contact     Gamer ID
    Join Date
    Apr 2011
    Location
    Calgary, Alberta, Canada
    Posts
    4,684
    Points
    4,169

    Contact info:

    Youtube Channel: http://www.youtube.com/CheeseToastHax

    Default

    I know but in CFG, what does it do? Does it make arrays into 1 line codes?

    0 Not allowed! Not allowed!
    "It's better to lose an argument/debate then to win. Cause when you lose you grow as a person."
    -CheeseToast

  10. #10
    Banned
    Join Date
    May 2011
    Posts
    917
    Points
    1,182
         User Info     Contact     Gamer ID
    Join Date
    May 2011
    Posts
    917
    Points
    1,182

    Default

    I think so honestly. I know you use:
    Code:
    <menu>
      <title>My Own Mod Menu</title>
      <item>
        <name>Item 1</name>
        <cmd>say Item 1</cmd>
      </item>
      <item>
        <name>Item 2</name>
        <cmd>say Item 2</cmd>
      </item>
      <item>
        <name>Item 3</name>
        <cmd>say Item 3</cmd>
      </item>
      <item>
        <name>Item 4</name>
        <cmd>say Item 4</cmd>
      </item>
      <item>
        <name>Item 5</name>
        <cmd>say Item 5</cmd>
      </item>
    </menu>
    In cgf modding. so it must be.

    0 Not allowed! Not allowed!

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -10. The time now is 06:06 AM.
Powered by vBulletin®
Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.