Jump to content

New to programming/modding, help with arrays


Nexusboiz

Recommended Posts

I'm trying to get a reference to an enemy from an array in OBSE to store as a ref variable and then use that as a condition for something else.

 

When testing on a single enemy, If I enter combat I get an error because of let b:= arrattackers[0]. Shouldn't arr_attackers point to the same array as PlayerRef.GetTargets and then the value stored as the key arr_attackers[0] be usable in the reference variable b?

 

scn aaCrt

float timer
float fQuestDelaytime
array_var arrattackers
Ref b


Begin GameMode

set fQuestDelaytime to 0.25

if Player.IsInCombat == 1

let arrattackers := PlayerRef.GetTargets
let b := arrattackers[0]












endif




End

Link to comment
Share on other sites

You code like a line coder from the late 80's and we did that because we did lack RAM. I started to code on 4kb computers and there we used variable names like A and B and I. :D

 

I stongly suggest you use full variable names like this:

array_var AttackersArr
Ref AttackersRef

as now we do not lack RAM any more... :wink:

 

You forgot to initiate the array and it cant be used until you made it this way

let AttackersArr := ar_Construct Array
Edited by Pellape
Link to comment
Share on other sites

 

You code like a line coder from the late 80's and we did that because we did lack RAM. I started to code on 4kb computers and there we used variable names like A and B and I. :D

 

I stongly suggest you use full variable names like this:

array_var AttackersArr
Ref AttackersRef

as now we do not lack RAM any more... :wink:

 

You forgot to initiate the array and it cant be used until you made it this way

let AttackersArr := ar_Construct Array

Thanks for the tip on the variables, i was just using those as placeholders to figure out what I was doing. I already constructed the array but in the documentation it said it was unnecessary if you were assigning it the return value of a command returning an array such as GetTargets?

Link to comment
Share on other sites

You cannot usean array, no matter what value you try to add to it if it doesn't exist as it will not exist until you initiate it -> making it.

let AttackersArr := ar_Construct Array

Look at the end, in this case it is a simple array but arrays can be of 3 different kinds so that is the main purpose with that whole line as well, to tell the game which type of arrays you will use. We are debating this in another thread right now as well and we do have so damn nice example scripts there now, just made this week.

Edited by Pellape
Link to comment
Share on other sites

Actually I think Nexusboiz is right. The array does not need to be constructed, if it's used as the target of a function returning an array. But QQuiz will know better than me which one is right. Additionally it won't hurt to first construct it and then overwrite it with the function's return either, to play it safe. But think of it like the "ar_Construct" call is taking place -inside- the "GetTargets" function call.

 

However, the "GetTargets" function does sound like it won't really work when called on the player but only when called on NPCs. You know, the game's internal combat AI handling, who's to attack who. Additionally I recall discussions from the past where no easy solution could be found to get a reference to the enemies currently attacking the player. So this function having been the solution all the time would be surprising.

 

There is a simple way to check that though. If "ar_Size arrattackers" returns "0", as in a mandatory check before trying to access a potentially inexistent array index, then the function didn't return any attackers.

Link to comment
Share on other sites

The CS will accept that you skip constructing the array for sure as the compiler do only check a single line at a time and cannot see the whole forest because the trees in its way.

 

When i started to use arrays in game, it failed. Compiling was not the issue but using the array was. I cannot say that I am 100% sure of this though, but I feel I am 99.98% sure though as it doesn't hurt to add the construction anyway so just do it and be sure it does work. I could be out somewhere bicycling, mostly on the garret

Link to comment
Share on other sites

You are right: you do not have to pre-initialize an array_var if you are 'pointing' it to an existing (initialized) array.

 

Array_var's are like c++ pointers. You may have multiple array_var's pointing to the same arrary.

 

Example:

array_var A
array_var B
array_var C

  let A := ar_construct array
  let B := A          ;--- Now, A and B point to the same array

  ;--- By the way . . . ---
  let A := ar_null   
  ;--- Now, A points to null, but the array itself remains intact because 
  ;---  OBSE knows that there are other array_var's  still pointing to it

  let B := ar_null     
  ;--- Now, B points to null, and the array is destructed  because 
  ;---  OBSE knows that B was the last array_var pointing to it


  let C := SomeRef.GetTargets          ;--- C now points to the array returned by GetTargets.

Link to comment
Share on other sites

Yes . . . in order for an array to exist, somebody has to build it, right?

 

After it is built, you can pass it around, so other pieces of code may use it (and change it). (actually, pass his location/address around, so other pieces of code may access it)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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