Jump to content

Arrays in Questscripts?


Recommended Posts

You're making good use of the "1 array per kind of data with identical indices each" concept in your scripts so far.

 

But you can definitely store a ref and 6 floats in 1 array index, very handily accessible even, if you use an array of StringMaps.
I am, or was, doing it quite a lot in my own scripts, as I'm used to data structures like these from database interfacing, data modeling, in PHP, Java, C and stuff.

[
    0: {
        ref: "ff345a",
        posX: 10.5,
        posY: 10.5,
        posZ: 0.0,
        angX: 0.0,
        angY: 0.0,
        angZ: 0.0
    },
    1: {
        ref: "ff345b",
        posX: 10.6,
        posY: 10.6,
        posZ: 0.0,
        angX: 0.0,
        angY: 0.0,
        angZ: 0.0
    },
    ...
]

(That's closer to JSON actually, but it's easier understandable what the structure is.)

In ObScript with OBSE it'd be set up like this:

array_var aMyList
 
...
 
let aMyList := ar_Construct Array
 
let aMyList[0] := ar_Construct StringMap
let aMyList[0]["ref"] := <some ref ID>
let aMyList[0]["posX"] := 10.5
let aMyList[0]["posY"] := 10.5
let aMyList[0]["posZ"] := 0.0
let aMyList[0]["angX"] := 0.0
let aMyList[0]["angY"] := 0.0
let aMyList[0]["angZ"] := 0.0
 
let aMyList[1] := ar_Construct StringMap
let aMyList[1]["ref"] := <some ref ID>
let aMyList[1]["posX"] := 10.6
let aMyList[1]["posY"] := 10.6
let aMyList[1]["posZ"] := 0.0
let aMyList[1]["angX"] := 0.0
let aMyList[1]["angY"] := 0.0
let aMyList[1]["angZ"] := 0.0
 
...
 
;You can even iterate over this construct later as usual:
 
array_var aItem
 
ForEach aItem <- aMyList
    PrintToConsole "item index: %.0f, item name: %n", aItem["key"], aItem["value"]["ref"]
    PrintToConsole "pos: (%f, %f, %f)", aItem["value"]["posX"], aItem["value"]["posY"], aItem["value"]["posZ"]
    PrintToConsole "ang: (%f, %f, %f)", aItem["value"]["angX"], aItem["value"]["angY"], aItem["value"]["angZ"]
Loop

Needless to say in my scripts I'm often using functions to create 1 StringMap item per call. Typing out a "let" for every index and every field each will quickly become a typing overkill.

Link to comment
Share on other sites

I do recognize the first example, as it looks almost exact as when you define arrays in C, 2 Dimensional arrays, like a bloody spreadsheet which I have used some approx 25 years ago. I will try your StringMap example later really as it looks very good. :smile: Now I finally get what StringMap is. Not that it matters for the player, but it sure matters to me when I read my own codes, having them as structured and easy to read as possible. I could make more comments in it as well when I think about it really and take good time making it and not rush it.

 

Damn I remember now. I made a program that prints out coupon's with a system I used to use for 1x2, soccer (football)... I entered a single row with 1,x or 2, gave them different piority depending on the likeness for one team would dominate the other in each match of the 13 matches, pushed print and out came 750 rows printed on 16 coupons from the printer :D I used arrays for it, exactly what you did show. I had an idea to remake the program with Q for Linux, but Q doesn't make sense for me as it is to much object oriented, so I only made the interface... Nothing else... It did look so simple to use... I usually managed to get 9-11 hits but never 12 nor 13. i also put in the final result in that program and it told me how many hits I got as well. I do not know the proper english word for it and Google translate do not have a clue.

 

Odd. I did make it with Visual Basic, which I forgot how to use now but the principle must be the same anyway.

Edited by Pellape
Link to comment
Share on other sites

Visual Basic is the 3rd language I learned. The language is Basic still, but it's also got a drag&drop editor to piece together windows and dialogues. Then you can right-click on buttons (or similar) and add Basic code for what to do when it's clicked.

Hmm, that was in 7th class I think. Man, that's far back in the past.

Link to comment
Share on other sites

Yes. I did learn to use it when I was doing my technician classes. We did VB, and also VBA, Visual Basic for Applications, which you find in your bloody Word and Excel editor or in every damn Office application.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...