User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17

Thread: Regarding arrays

  1. #1
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.59%

    Regarding arrays

    Code:
    const int numQuests = 1;
    bool questGotten[numQuests];
    bool questCompleted[numQuests];
    bool questRewarded[numQuests];
    int  questGotStrings[numQuests] = {1};
    int  questCompleteStrings[numQuests] = {2};
    Quote Originally Posted by the compiler
    Pass 1: Parsing
    Pass 2: Preprocessing
    line 2: syntax error, unexpected IDENTIFIER, expecting NUMBER, on token numQuests
    tmp, line 1: Error P01 : Failure to parse imported file quest.z.
    So, we can't use constants to declare arrays? That seems... annoying. Is this a bug, or just something that hasn't been thought of yet?

    PS: I seem to recall at one point support for strings in ZScript. Am I insane? Now, I can't find any reference to this...

    Edit for good measure:

    Quote Originally Posted by jman, a long long time ago
    * And finally, the additions of arrays to the scripting engine! Took a lot of work, but they're in. Now, each running script has the option via the global Declare() function to allocate for itself a block of memory. This block of memory is used as a scratch space for declaring and using arrays. One block is continually persistent as a 'global' memory and is used by default when an ffc or item script doesn't declare a piece of memory. Also included is a new section of memory in save files that allows you to store whatever miscellaneous data you like. ( jman2050, 2008-03-04 11:27:42 )
    How does one use Declare()? Is this a function (it's not in zscript.txt)? Or, a construct of some sort (it's not on the wiki)? Or... what? I'm trying to make my arrays save, but it's not going very good right now.
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  2. #2
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,304
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.76%

    Re: Regarding arrays

    We're not allowed variable sized arrays.
    I don't think anyone actually worked out what Declare()'s meant to do.
    There's a bug with saving arrays currently.

    And I believe (though I may be wrong cause I never used it) that you can make a string like this:
    Code:
    int newstring = "I'm a string";
    But there's currently no real purpose for it.

  3. #3
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.59%

    Re: Regarding arrays

    Quote Originally Posted by Joe123 View Post
    We're not allowed variable sized arrays.
    Well, yes. But, it's a constant. See your thread

    Quote Originally Posted by Joe123 View Post
    I don't think anyone actually worked out what Declare()'s meant to do.
    I would like to hear something official about this. I added it to my script as is ("Declare()"), and it accepted it... and, I haven't seen any difference.


    Quote Originally Posted by Joe123 View Post
    There's a bug with saving arrays currently.
    Curses.

    Quote Originally Posted by Joe123 View Post
    And I believe (though I may be wrong cause I never used it) that you can make a string like this:
    Code:
    int newstring = "I'm a string";
    But there's currently no real purpose for it.
    Hmm. Your form didn't work, but this did:

    Code:
    int test[10] = "Testing?";
    Interestingly, this does have some use (manually drawing a string via tiles, etc), although, not much. If we had multi-dimensional arrays, we could do something like:

    Code:
    int test[3][20] = { "Quest 1", "Quest 2", "Quest 3" };
    Which would be awesome. But, we can't Not directly, anyway...

    Code:
    int test[60] = "Quest 1             Quest 2             Quest 3             ";
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  4. #4
    Octorok CaRmAgE's Avatar
    Join Date
    Oct 2008
    Location
    Historia
    Age
    35
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,335
    Level
    12
    vBActivity - Bars
    Lv. Percent
    42.9%

    Re: Regarding arrays

    Quote Originally Posted by pkmnfrk View Post
    Well, yes. But, it's a constant.
    The point is the size of a static array needs to be determined during compile time for allocating memory purposes, just like all other static variables. Thus, you can't use variables at all to define array size, even constant ones; while you may view "numQuests" as a constant value, the compiler sees just another variable.

    The only way you could possibly use variables to initialize an array's size is by creating an array that determines it's size at run time (dynamic arrays). But since...

    Quote Originally Posted by Joe123 View Post
    We're not allowed variable sized arrays.
    ...in other words, dynamic arrays, using variables to set an array's size isn't possible right now. Sorry.

  5. #5
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.59%

    Re: Regarding arrays

    Quote Originally Posted by pkmnfrk View Post
    Interestingly, this does have some use (manually drawing a string via tiles, etc), although, not much.
    I take this back. They have zero use as implemented.

    Code:
    int charWidth[96] = {5,3,7,7};
    
    int string_buf[255];
    
    const int string_tile = 14300;
    
    global script onStart {
    	void run() {
    		string_buf = "#!#";
    		while(true) {
    			drawString(string_tile, 2, 3, 0, 0);
    			Waitframe();
    		}
    	}
    }
    
    void drawString(int s_tile, int cset, int lay, int x, int y) {
    	int dx, dy;
    	dx = x;
    	dy = y;
    	
    	int tile;
    	
    	
    	for(int i = 0; i < 255; i++) {
    		if(string_buf[i] < 32) {
    			if(string_buf[i] = 10) {
    				dy += 8;
    				dx = x;
    			}
    		} else {
    			tile = string_buf[i] - 32;
    			Screen->DrawTile(lay, dx, dy, tile + s_tile, 1, 1, cset, 1, 1, 1, 0, 0, true, 128);
    			dx += charWidth[tile];
    		}
    	}
    }
    You can't assign to string_buf in any way (other than manually assigning each element), and you can't pass arrays as parameters. For these fake string array things to be useful, you need to be able to do one or the other... I personally don't care which.
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  6. #6
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.59%

    Unhappy Re: Regarding arrays

    Ok, I give up.

    What I was trying to do (as I alluded to above) is, essentially, implement drawing strings via a "tile font" (variable width, with the widths in the charWidth[] array). But, it's impossible.

    My first idea was to pass a string to drawString, but since you can't pass arrays, this is out.

    My next idea was to have a global "string buffer", into which you put your string, and then drawString draws from it. But, you can't assign strings outside of a variable initializer (right?), so that limits it to... the very first string you have in the game.

    My last idea was to have the draw string routine in a separate file, and include it in all the places you would use drawString. You would have to use the same array name in all these places, but at least you can draw more than one string, right?

    No, you can't "import" inside a function. For the love of...

    Anyone else have any ideas? Or, am I wasting large amounts of time on something that just is not possible currently?
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  7. #7
    The Time-Loop Continues ZC Developer
    Gleeok's Avatar
    Join Date
    Apr 2007
    Posts
    4,826
    Mentioned
    259 Post(s)
    Tagged
    10 Thread(s)
    vBActivity - Stats
    Points
    12,959
    Level
    33
    vBActivity - Bars
    Lv. Percent
    26.22%

    Re: Regarding arrays

    Don't give up!!!

    This has actually been on my to do list for a while. I just finished upgrading my quest to 887, and would be happy to help out in getting some scripted string functions working. ...At least I think that's what you're doing. Hmm... :)

    Lemme just take a look at what you've got there....


    Edit1; Do ascii characters have a numerical value in ZScript, and what would they be? - EDIT3; Goddamnit. Nevermind. These are completely useless.

    Edit2; Well here's a thought: No, you cannot pass an array in ZScript, But, you can have global arrays. What I'm getting at here is that you can have a temp_array[] and simply copy the data of a global array into that, for temorary use with a function.

    Edit4; Well this is prop8 gay, but you're right, you can't initialize an array with int or const. gay.


    So...What we're looking at here is having to type sentences with numbers instead of letters..blah. I'll mess with it tomorrow.
    This post contains the official Gleeok seal of approval. Look for these and other posts in an area near you.

  8. #8
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.59%

    Re: Regarding arrays

    Quote Originally Posted by Gleeok View Post
    Don't give up!!!

    This has actually been on my to do list for a while. I just finished upgrading my quest to 887, and would be happy to help out in getting some scripted string functions working. ...At least I think that's what you're doing. Hmm... :)

    Lemme just take a look at what you've got there....


    Edit1; Do ascii characters have a numerical value in ZScript, and what would they be? - EDIT3; Goddamnit. Nevermind. These are completely useless.
    Yup, they have standard ASCII values. They're not useless, see below for more thoughts.

    Quote Originally Posted by Gleeok View Post
    Edit2; Well here's a thought: No, you cannot pass an array in ZScript, But, you can have global arrays. What I'm getting at here is that you can have a temp_array[] and simply copy the data of a global array into that, for temorary use with a function.
    Well, no need for a global. But...

    Quote Originally Posted by Gleeok View Post
    Edit4; Well this is prop8 gay, but you're right, you can't initialize an array with int or const. gay.
    Or re-init an array with a string. However...

    Quote Originally Posted by Gleeok View Post
    So...What we're looking at here is having to type sentences with numbers instead of letters..blah. I'll mess with it tomorrow.
    My idea was to use method 2 (in my post), and have a separate utility that basically takes a list of strings, and outputs a chunk of code. Eg:

    Input:
    Code:
    ABC
    123
    Output:
    Code:
    int string_buf[4]; //auto-sized to the largest string
    
    void loadString(int num) {
    	if (num==1) {
    		string_buf[0] = 65; string_buf[1] = 66; string_buf[2] = 67; string_buf[3] = 0;
    	} else if(num==2) {
    		string_buf[0] = 48; string_buf[1] = 49; string_buf[2] = 50; string_buf[3] = 0;
    	} else {
    		string_buf[0] = 0;
    	}
    }
    And then, in your script file, you do this:

    Code:
    import "std.zh"
    import "strings.zh"
    
    //...
      loadString(2);
      drawString(16, 16, 2, 6);
    //...
    Ideally, this would become obsolete very quickly.

    Edit: The only potential problem with this is that if you have a lot of strings, and a lot of scripts, this will likely fill up whatever script space we have very quickly.
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  9. #9
    The Time-Loop Continues ZC Developer
    Gleeok's Avatar
    Join Date
    Apr 2007
    Posts
    4,826
    Mentioned
    259 Post(s)
    Tagged
    10 Thread(s)
    vBActivity - Stats
    Points
    12,959
    Level
    33
    vBActivity - Bars
    Lv. Percent
    26.22%

    Re: Regarding arrays

    Alright, I'm pretty much finished with it. Although I still can't understand how it may be possible to convert a "string" into data read by an array in ZScript. (At least I think that's what you're doing..?) I couldn't quite figure it out without using arrays, (and they are currently very limited in use) so each string requires one array. Perhaps you can take a look at it when it's done?

    ..Which reminds me: Anyone wan't to post up a ripped .gif of some letters? Up to 8 pixels wide would be fantastic. :)
    This post contains the official Gleeok seal of approval. Look for these and other posts in an area near you.

  10. #10
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.59%

    Re: Regarding arrays

    Last things first, a font as used by drawString is one tile per character. The standard size is 8px high, with a variable width. Originally, I was going to have a maximum size of 8x8, but I then realized you can't draw a sub-tile with ZScript :'(

    Anyway. A string, in any language, is just a sequence of numbers that happen to correspond to certain codes in an ASCII table, which make coherent sentences. "A" is 65, "B" is 66, "4" is 52, etc.

    Internally, when assigning a string to an array, ZScript just takes the numeric value of each letter, and puts it in the appropriate slot of the array (and, adds a zero at the end to indicate that the string is done).

    To work around the lack-luster support for strings in ZScript, I would write a wholly separate program that takes a bunch of strings, and creates a function which manually loads those strings into a certain buffer (for use with drawString). The program would do something like this:

    Code:
    print out function header
    i = 1
    for each line
      print "case " & (i++)
      j = 0
      for each character in the line
        what is the value of that character?
        print "string_buf[ " & j++ & "] = " & the value of the character & "; "
      next character
      print "string_buf[" & j++ & "] = 0;\n"
      print "break;\n"
    next line
    print out function footer
    This would result in the function I posted in my last post. You'd add 'include "strings.zh"' to your script file, and away you go.

    I think I should just do it, and you'll be able to see how it works...
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

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