User Tag List

Results 1 to 4 of 4

Thread: Arrays!

  1. #1
    Is this the end?
    ZC Developer
    Saffith's Avatar
    Join Date
    Jan 2001
    Age
    41
    Posts
    3,389
    Mentioned
    178 Post(s)
    Tagged
    6 Thread(s)
    vBActivity - Stats
    Points
    6,451
    Level
    24
    vBActivity - Bars
    Lv. Percent
    73.19%

    Arrays!

    I'm sure it's something that's been considered already, but we could really do with arrays. I realize variable-size arrays are probably pretty difficult, considering how variables work, but even fixed-size arrays would be quite helpful.

    There are two specific situations I've already encountered in which they'd be useful:
    - Setting the amount of damage done to an FFC-based enemy by different levels of weapons (especially helpful since we may not know in advance how many levels there are)
    - Defining songs and recording notes for a playable ocarina

    Fixed-size arrays shouldn't be hard to implement, I think. Just like a series of distinct variables. As far as access, array[i] could, at worst, be handled internally the same way as
    Code:
    if(i==0)
       array[0];
    else if(i==1)
       array[1];
    // etc

  2. #2
    Wizrobe C-Dawg's Avatar
    Join Date
    Jan 2002
    Posts
    4,205
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    6,630
    Level
    25
    vBActivity - Bars
    Lv. Percent
    2.86%

    Re: Arrays!

    I offer my infintely less wise concurrance to this request.

    I've run into at least two situations where fixed-size arrays would be very handy.

    (1) Coding a "snake" like entity. The script would calculate the movement of the snake, but instead of applying it directly to the FFCs making up the snake's body, it puts the resulting data into a queue. Each tic, the next movement data for the snake moves into the queue and pushes the other data over one. Last, each segment of the snake takes it's position / velocity from a different element in the queue. The result is that the body of the snake follows the head around the room.

    (2) Saving Link's inventory. I'd like to be able to mirror link's inventory in an array, so in addition to viewing items on the subscreen, there would be a second, invisible array keeping track of what Link has picked up. This would let you switch items on and off at the user's whim. In particular, this would allow multiple playable characters, each who can use only certain items, and let the user switch between those characters as necessary.

  3. #3
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,047
    Level
    31
    vBActivity - Bars
    Lv. Percent
    10.69%

    Re: Arrays!

    I'd thought about arrays when I was first designing ZScript and postponed working on them because they are complicated. Very rudimentary, static, fixed size arrays, such as
    Code:
    ffc script foo {void run() {
      int anarray[3];
      anarray[someMethodReturningInt()]=42;
    }
    }
    would not be terribly difficult to implement.

    One thing to keep in mind is that the arrays will have to be stack-allocated, and the stack is currently capped at 256 elements. The stack is used as follows:
    -Each local variable in the current method and all methods in the call hierarchy takes one slot.
    -Each parameter of the current method and all methods in the call hierarchy takes one slot.
    -For each method in the call hierarchy, two additional slots are taken up - one for the return value, and one for the old value of the stack frame pointer. This adds up when recursively calling functions.
    -Evaluation of expressions requires up to two temporary slots for storing intermediate values.

    Thus to ensure the script doesn't crash due to stack overflow the total space reserved for arrays will have to be kept small. Alternatively, we could add a free store common to all scripts and talk about dynamic allocation or even garbage collection

  4. #4
    Gel
    Join Date
    Jan 2007
    Age
    39
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    731
    Level
    9
    vBActivity - Bars
    Lv. Percent
    51.74%

    Re: Arrays!

    There is *sometimes* a way, depending on how strict a language is with both global/function-local variables/arrays, and also how strict with declaration.

    It would be easier if you could redefine an array after you initially declare it.

    But I'm pretty sure if you do, for instance,

    int myvar = 2;

    int myvar = 34;

    It yells at you. I could be wrong. Maybe it only yells when you try to change types.

    Anyways. If you can't redeclare an already existing array, if you can UNDECLARE it then you can use a temporary array to store all it's values, undeclare it, declare it at the new length, add the values back in, and any extra values you were wanting to add in. You could remove values by a similar process, only this time you'd be copying a few *less* values from the temp array back to the new, smaller array.

    You'd of course want to undeclare the temp array. But you could potentially make array_add and array_remove sort of functions this way.

    With a little more work, even array_sort and beyond...

    Anyways. Just something I've done to dynamicize my arrays in languages that didn't come with dynamic arrays, and I thought I'd share. Arrays at all would be YES, most DEFINITELY AWESOME. ^_^

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 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