What are the advantages of an array?

Post » Fri Feb 18, 2011 10:41 pm

I'm slowly starting to understand array's. I can see how I can implement them in my mod, but I don't quite understand the advantages of them.

So what are the advantages of an array?
User avatar
RAww DInsaww
 
Posts: 3439
Joined: Sun Feb 25, 2007 5:47 pm

Post » Sat Feb 19, 2011 1:26 am

If you have a lot of data you need to manipulate, you can use an array to store the values, instead of having to create a variable for each item. There are also functions that will dump various things to an array, like... player inventory. :D
User avatar
Loane
 
Posts: 3411
Joined: Wed Apr 04, 2007 6:35 am

Post » Sat Feb 19, 2011 9:14 am

Ah, okay. So how many variables, do you think, would constitute "a lot"? I'm considering using an array for the current script I'm working on. But I don't need a lot of variables to do what I want to do.

You always answer my questions quickly, HeyYou. I appreciate that.

While I have you reading this thread, let me ask another question:

I am tracking damage done to the PC. The way I'm doing it is by tracking when base health is == to current health If current health drops, I do something. Is there a more efficient way to do that? Would an array used in this instance cut down on precessing?
User avatar
Quick Draw III
 
Posts: 3372
Joined: Sat Oct 20, 2007 6:27 am

Post » Sat Feb 19, 2011 11:09 am

"a lot" is just a matter of preference really. In some instances, an array is easier to use than a selection of variables. have a look at what you are doing, and try and determine from there if an array would make your life easier.

Not sure if there is any better way. I assume you are using a quest script for that? I think the only real 'efficiency' thing there, would be just how often the quest runs (fquestdelaytime) Gotta have it run often enough, that it will catch events that happen in rapid succession, such as, when facing multiple enemies.

Perhaps just have a short script monitoring health, and when it actually needs to do something, use a function call?

Edit: You're welcome. :D I am not a top notch scripter, so, if I don't know, I simply don't respond. :D
User avatar
LADONA
 
Posts: 3290
Joined: Wed Aug 15, 2007 3:52 am

Post » Sat Feb 19, 2011 4:34 am

Okay. Thanks again. I'll just go with what I was going to do originally.
User avatar
Jordan Fletcher
 
Posts: 3355
Joined: Tue Oct 16, 2007 5:27 am

Post » Sat Feb 19, 2011 11:53 am

Would this be valid (trying to determine if the PC has a shield equipped -- any shield)?
Using a string variable (there may be a better way, but I can't seem to find the function):

set string1 to sv_construct player.getequippedobject 13           if sv_length string1 > 1                      do something


??
User avatar
Sierra Ritsuka
 
Posts: 3506
Joined: Mon Dec 11, 2006 7:56 am

Post » Fri Feb 18, 2011 9:09 pm

I go about it slightly differently. Not to say mine is better. Just different.


Ref Armorset armor to player.getequippedobject 13If armor != 0....     dostuff

User avatar
Jessica Nash
 
Posts: 3424
Joined: Tue Dec 19, 2006 10:18 pm

Post » Fri Feb 18, 2011 11:27 pm

Oh okay, my noobness got me there. Which version, mine or yours, is less CPU intensive?

That's the one I'll use.
User avatar
Julia Schwalbe
 
Posts: 3557
Joined: Wed Apr 11, 2007 3:02 pm

Post » Fri Feb 18, 2011 11:31 pm

Don't know.... :D If I had to hazard a guess though, I would say probably mine, all vanilla functions.
User avatar
Richus Dude
 
Posts: 3381
Joined: Fri Jun 16, 2006 1:17 am

Post » Sat Feb 19, 2011 3:03 am

Righto. I'll use yours then.

Thanks again.
User avatar
Emzy Baby!
 
Posts: 3416
Joined: Wed Oct 18, 2006 5:02 pm

Post » Sat Feb 19, 2011 7:28 am

So what are the advantages of an array?

You can...
  • store values, where you don't know how many you'll need while writing the script. I.e. storing every weapon the player had equipped for whatever reason.
  • use it to return more then one value with a user function
  • use it as a way to pass a multi-argument to a User Function

  • etc.


I am tracking damage done to the PC. The way I'm doing it is by tracking when base health is == to current health If current health drops, I do something. Is there a more efficient way to do that? Would an array used in this instance cut down on precessing?


Why not use a OnHealthDamage-http://www.obse.silverlock.org/obse_command_doc.html#Events?

Would this be valid (trying to determine if the PC has a shield equipped -- any shield)?Using a string variable (there may be a better way, but I can't seem to find the function):
set string1 to sv_construct player.getequippedobject 13           if sv_length string1 > 1                      do something
??


No. sv_Construct expects a format_string as argument, not a function returning a formID.

If you want to use the string-method it could work in a http://www.obse.silverlock.org/obse_command_doc.html#Compiler_Override-Block using one of these three lines:
let string := GetName ( GetEquippedObject 13 )let string := GetFormIDString ( GetEquippedObject 13 )let string := $GetEquippedObject 13               ;returns the FormID IIRC

Or use a Dummy-Ref, then you could use this without a compiler override.


Oh okay, my noobness got me there. Which version, mine or yours, is less CPU intensive? That's the one I'll use.


Not really sure about CPU intensitivity (if you don't use loops that shouldn't matter, btw.), but since both methods call GetEquippedObject and only one uses another function afterwards I'd guess the one with the ref-var is faster.


If you want to know if the shield is really used (and not only equipped; i.e. using a bow) I'd suggest using http://cs.elderscrolls.com/constwiki/index.php/IsShieldOut instead.


PS:
GetEquippedObject is not a Vanilla-Function. ;)




Edit:
A little bit too slow, I guess. :P
User avatar
krystal sowten
 
Posts: 3367
Joined: Fri Mar 09, 2007 6:25 pm

Post » Sat Feb 19, 2011 1:49 am

But not too late. Wasn't aware of the OnHealthDamage event. Cool. Learned something new. :D
User avatar
Jessie
 
Posts: 3343
Joined: Sat Oct 14, 2006 2:54 am

Post » Sat Feb 19, 2011 12:11 am

Probably mentioned by the gurus who've already graced this thread with their presence - Runtime/dynamic variable creation.
User avatar
Dezzeh
 
Posts: 3414
Joined: Sat Jun 16, 2007 2:49 am

Post » Sat Feb 19, 2011 8:17 am

So what are the advantages of an array?

You can...
  • store values, where you don't know how many you'll need while writing the script. I.e. storing every weapon the player had equipped for whatever reason.
  • use it to return more then one value with a user function
  • use it as a way to pass a multi-argument to a User Function

  • etc.



Very nice. I am starting to learn how to use them. I can see the advantages now that you pointed them out.

Why not use a OnHealthDamage-http://www.obse.silverlock.org/obse_command_doc.html#Events?


That's what I am going to do, but I am confused by the format of the script the event handler calls. I asked in the OBSE thread for some clarification. If you read this before they respond, perhaps you could help me.

All I want to know is how to set the "Begin" block.

Is it
Begin Function {1 GetSelf}


To set the damage to 1 or more, and set the reference to the player?

No. sv_Construct expects a format_string as argument, not a function returning a formID.

If you want to use the string-method it could work in a http://www.obse.silverlock.org/obse_command_doc.html#Compiler_Override-Block using one of these three lines:
let string := GetName ( GetEquippedObject 13 )let string := GetFormIDString ( GetEquippedObject 13 )let string := $GetEquippedObject 13               ;returns the FormID IIRC

Or use a Dummy-Ref, then you could use this without a compiler override.


Ah, okay. That helps me understand strings more. I can see the potential for that.

Not really sure about CPU intensitivity (if you don't use loops that shouldn't matter, btw.), but since both methods call GetEquippedObject and only one uses another function afterwards I'd guess the one with the ref-var is faster.


The CPU requirements are probably not noticeable between the two.

If you want to know if the shield is really used (and not only equipped; i.e. using a bow) I'd suggest using http://cs.elderscrolls.com/constwiki/index.php/IsShieldOut instead.


I didn't even know there was such a function. Must have skipped it when I was function hunting. :)

Thanks for the help, Low Post.
User avatar
Lyndsey Bird
 
Posts: 3539
Joined: Sun Oct 22, 2006 2:57 am


Return to IV - Oblivion