User Tag List

Results 1 to 10 of 115

Thread: AngelScript: The Revenge

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Username Kaiser SUCCESSOR's Avatar
    Join Date
    Jul 2000
    Location
    Winning.
    Age
    37
    Posts
    4,436
    Mentioned
    152 Post(s)
    Tagged
    7 Thread(s)
    vBActivity - Stats
    Points
    10,566
    Level
    30
    vBActivity - Bars
    Lv. Percent
    52.46%
    Quote Originally Posted by Moosh View Post
    I mostly do it because my waitframe functions tend to get more and more arguments as I work on a boss. Every time the number of arguments changes I have to change every instance of those functions, so it's faster to just cram most of them in an array.

    So for a boss with laser attacks I might have something like this:
    Code:
    int laserX[32]; //Laser X position
    int laserY[32]; //Laser Y position
    int laserA[32]; //Laser angle
    int laserW[32]; //Laser width
    int laserT[32]; //Laser timer
    int vars[16] = {laserX, laserY, laserA, laserW, laserT};
    
    
    void Example_Waitframe(ffc this, npc ghost, int vars){
    	Example_UpdateLasers(this, ghost, vars);
    	Ghost_Waitframe(this, ghost, true, true);
    }
    void Example_UpdateLasers(ffc this, npc ghost, int vars){
    	int laserX = vars[0];
    	int laserY = vars[1];
    	int laserA = vars[2];
    	int laserW = vars[3];
    	int laserT = vars[4];
    	for(int i=0; i<SizeOfArray(laserX); i++){
    		//pretend this is actually doing something
    	}
    }
    I see no use in doing this with global arrays so no worries there. And echoing what Grayswandir said, I learned to do this from looking at some of Saffith's scripts. I LEARNED IT FROM YOU, DAD! I LEARNED IT FROM WATCHING YOU!
    O.o

    You can do this?! Why do you do this? Why not just pass one big laser array?

  2. #2
    Keese
    ZC Developer

    Join Date
    Jan 2007
    Age
    34
    Posts
    52
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    vBActivity - Stats
    Points
    784
    Level
    9
    vBActivity - Bars
    Lv. Percent
    82.56%
    Right. While we're speaking of the horrors of zscript, I realized I never mentioned the latest bit I cooked up:
    Code:
    //////////////////////////////////////////////////////////////////
    // Pointers are numbers holding a reference to a specific index of a specific
    // array. This library deals with the creation and manipulation of pointers.
    //
    // Pointers are numbers that are split into 2 parts. The integer portion of
    // the number (XXX.0000) is the pointer's index into the zscript array. The
    // decimal portion of the number (000.XXXX) is the number of the zscript array
    // which the pointer is pointing into.
    //
    // All functions, if the array number is 0, will instead treat the integer
    // portion as the array number, and assume an index of 0. This lets you treat
    // arrays themselves as pointers to their 0 index.
    
    
    ////////////////////////////////////////////////////////////////
    // Creation
    
    
    // This creates a pointer to a given array. If given a pointer itself, it will
    // do nothing and return it instead.
    int GP_Pointer(int arg) {
        // If arg is a pointer, just return it.
        if (10000 * (arg % 1)) {return arg;}
        // Otherwise, create a new pointer to the first spot in the array.
        return 0.0001 * arg;}
    
    
    // This takes an array or a pointer, and returns a new pointer offset from the
    // first by the given amount.
    int GP_Pointer(int pointer, int offset) {
        // If arg is a pointer, just add the offset to it.
        if (10000 * (pointer % 1)) {return pointer + offset;}
        // Otherwise, create a new pointer from the array.
        return 0.0001 * pointer + offset;}
    
    
    ////////////////////////////////////////////////////////////////
    // Manipulation
    
    // Return the value that the pointer is pointing at, with the index offset by
    // the given number.
    int GP_Pointer_Get(int pointer, int offset) {
        // If pointer is actually an array, just return the 0 position of that
        // array.
        int array = 10000 * (pointer % 1);
        if (!array) {return pointer[offset];}
        // Otherwise return the pointer's value. (Array lookup truncates, so we
        // don't need to.)
        return array[pointer + offset];}
    
    // Set the value of a pointer, with the index offset by the given amount.
    void GP_Pointer_Set(int pointer, int offset, int value) {
    	// If pointer is actually an array, just set the offset position of that array.
    	int array = 10000 * (pointer % 1);
    	if (!array) {pointer[offset] = value; return;}
    	// Otherwise, set the pointer normally. (Array lookup truncates, so we don't
    	// need to.)
    	array[pointer + offset] = value;}
    It works wonderfully. The only problem is it's a tad bit slow.

  3. #3
    Empty and become Moosh Moosh's Avatar
    Join Date
    Oct 2012
    Posts
    57
    Mentioned
    13 Post(s)
    Tagged
    4 Thread(s)
    vBActivity - Stats
    Points
    629
    Level
    8
    vBActivity - Bars
    Lv. Percent
    91.07%
    Quote Originally Posted by SUCCESSOR View Post
    O.o

    You can do this?! Why do you do this? Why not just pass one big laser array?
    Readability mostly. I find it easier to read when there's multiple parallel arrays than when there's one with a bunch of multiplication or an incomprehensible mess of nested setter and getter functions. I use the one big array method if I'm working with global arrays, but with FFC scripts I haven't been hurt yet by wasting a few variables.

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social