Jump to content

Arrays in Questscripts?


Recommended Posts

It's been months since I needed to use it, but I think I made a forum post somewhere asking for help about this kind of syntax. Just not sure where

Ok yeah I found the post: https://forums.nexusmods.com/index.php?/topic/8697298-how-do-arrays-of-arrays-function/
I was probably just misremembering everything, my memory isn't very good

Edited by KatsAwful
Link to comment
Share on other sites

Our memory is not like a computer for sure. We live here and now. The computer will remember forever until it breaks or something changes it... or you turn the power off without saving... :wink:

 

One exception, Notepad++ when I think about it. It saves every key you push somewhere, automatically. If you forget to save, Notepad++ doesn't care when you open it the next time again, as it is still there.

Edited by Pellape
Link to comment
Share on other sites

I use simple arrays. Lets say I have 1 array for a ref and 6 arrays for shorts, containing all 6 pos settings for that ref. If we do the opposite, described in the OBSE documentation, adding several values to one single array, how do I get all out from it separate?

 

Lets say I add a ref and 6 different shorts?

Edited by Pellape
Link to comment
Share on other sites

Just so I'm understanding right, you're asking about an array that contains 1 ref and 6 shorts?

 

Oblivion arrays aren't constrained to type, you can add any valid variable or value to an array in any combination assuming you follow the inherent rules of arrays. But also if you wanna process over a whole array you gotta make sure you're dealing with the right type first. Can't do math on a reference variable ofc

Link to comment
Share on other sites

Thanks but that is the basics, nothing advanced... :wink: It is the way I already use them. What I did wonder about was to add several different kinds of data into one single array and get them out again, Like this example from the OBSE documentation, in the Array Variables section, as this is what I was referring to:

	array_var a
	array_var b
	let a := ar_Construct Array
	let a[0] := "First elem"
	let b := a                  ; b now refers to the same array as a
	let b[1] := "Second elem"   ; array now contains two elements

They do cheat, as they do use 2 strings in that example, not 2 different types... :/ Then it is no problems to get the data out, just Let it to a bloody string :wink:

 

They still use several arrays as well and that was my initial idea, to be able to use less arrays but then it would require a lot of sorting to take the data apart, like searching for every letter in a bloody string, which I do in my current project in my display room. I did a video recording of it as well.

 

 

The script is analyzing every key that gets pressed, like when I typed r03 in the video. (Also watch the axe under the painting in the end...) ;)

 

I am fine as it is though, well for the moment at least as my arrays do what they are meant to do.

Edited by Pellape
Link to comment
Share on other sites

If I understand your question, the answer was in that WIKI page, in the StringMap example


Anyway, here is another example: the MyNPC array contains multiple types of entries: float, string and reference




;--- Main array
array_var MyNPC
let MyNPC := ar_Construct stringmap

ref MyRef
let MyRef := <Jonh'reference/FormID in game>

Let MyNPC["Reference"] := ref
Let MyNPC["FullName"] := "John Doe"
Let MyNPC["PosX"] := MyRef.getpos x
Let MyNPC["PosY"] := MyRef.getpos y
Let MyNPC["PosZ"] := MyRef.getpos z
Let MyNPC["AngX"] := MyRef.getangle x
Let MyNPC["AngY"] := MyRef.getangle y
Let MyNPC["AngZ"] := MyRef.getangle z




To access the data:




Let NPCref := MyNPC["Reference"]


;--- Not sure this works
NPCref.setpos x MyNPC["PosX"]


;--- Maybe the value must go to a float first
float posX
Let PosX := MyNPC["PosX"]
NPCref.setpos x PoxX


; etc, etc, etc ...

Edited by QQuix
Link to comment
Share on other sites

QQuix, the syntax for the ForEach item assignment was a touch wrong. I had to pass off 'item' to a variable in order for CSE to compile like so:

  ForEach item <- aArmor[iArmorRandom]
    let rTemp := item["value"]
    PlayerREF.AddItemNS rTemp 1	; add said value to player
    PlayerREF.EquipItemNS rTemp	; equip said value on player
  Loop

But otherwise everything else you posted was right

Link to comment
Share on other sites

Now I slowly start to understand StringMap. I am so used to Array, pointing at it with shorts and use while loops instead of foreach but it works nice for my purposes so far, no doubt but I really wanna test StringMap, just for test purposes if any, so to say. :) But how to control it? I have full control over my arrays at the moment and I can pick out data from anywhere in the array, with loops, comparing each data with the reference or object that I am searching for but I can do that as well if I peek at Kats example. I might think like an old dinosaur maybe? I did a lot of Ansi C 20-25 years ago but never any C++ specific coding as I do get a feeling if we now can compare them that StringMaps might be more object oriented? If it is one thing we do handle in all TES games, Daggerfall included is Objects and specially in Daggerfall, which amazes me more and more really.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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