Jump to content

Setting GV values in an Array


Rizalgar

Recommended Posts

Ok, so I'm new to Arrays, and I can't seem to figure this out. The idea behind this is to prevent writing a 6 thousand line script by use of arrays. It's a little hard to explain but I'll do my best.

 

I have 5 Global Variables, with a 6th Global controlled by a 7th Global. [stats 1-5, Level, Experience - In that order] with those Globals being controlled by an 8th Global [the "class"]

 

Basically, when the sufficient XP is gained, you level up, then the level up kicks in a DoOnce stat level that increases your stats based on your class (I've only managed to figure out the DoOnce part of it)

 

However, I can't seem to get it to apply the stat changes to the global variables. Again, I'm new to Arrays, so forgive me if this is just horribly incorrect. Here is an example of what I'm trying to do

 

 

 

Bool[] DoOnce = New Bool[59]
Int[] Warrior = New Int[59]
Int[] Warlock = New Int[59]

DoOnce == False

If Class == 1
  Warrior[0]
    Agility.SetValue(10)
EndIf

If Level == 1
  DoOnce[0]
  If Class == 1
    If DoOnce[0] == False
      Warrior[0]
      DoOnce[0] == True
    EndIf
  EndIf
EndIf


 

 

 

I'm sure I'm just going about this in the most wrong of ways, but I feel learning Arrays will be much quicker than writing out 5 stat changes for 9 classes for 60 levels with each class having different stats. My whole goal I guess is to store each class and levels stats in an Array, then issue those stat changes on level up.

 

Any help is greatly appreciated.

 

 

Edit -- Well, I kinda figured it out. If anyone could enlighten me on a cleaner, more efficient way of doing it, I would appreciate that. Here's the new code.

 

 

 

Bool[] DoOnce = New Bool[59]

Int[] Warrior1 = New Int[5]

Warrior1 = Agility.SetValue(10)
Warrior1 = Strength.SetValue(17)

If Level == 1
  DoOnce[0]
  If DoOnce[0] == False
    If Class == 1
      Warrior1
      DoOnce[0] == True
    EndIf
  EndIf
Endif

 

 

 

Because with that I may as well skip the array and just set the global directly without it

Edited by Rizalgar
Link to comment
Share on other sites

I'm not sure I understand what you're actually trying to do, but if you're trying to set, for example, 60 globals, provided you're not trying to read their values at the same time, yes you can do that with an array. Otherwise, you'll get threading issues where they wont change as expected unless you use mod().

 

short example:

GlobalVariable[] property gvArray auto
 
Function Foo()
int index = gvArray.length
 
while index
    index -= 1
    gvArray[index].SetValue(1.0)
endwhile
EndFunction

An alternate way of doing that:

int i
int index = gvArray.length
 
while i < index
    gvArray[i].SetValue(1.0)
    i += 1
endwhile

Also, I'm assuming you're using the storymanager for checking level ups. Using the Skill based storymanager might help make this a little easier too.

Edited by Rasikko
Link to comment
Share on other sites

  • Recently Browsing   0 members

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