Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Array question

clark

Villager
Xy$
0.00
lets say I have an array... ex [1, 7, 5, 8], named acva

and i did this:

var acva2 = acva.split(" ");

for (var i = 0; i < acva2.length; i++) {
if (Number(acva2[-i-]) <= 2)
this.doStuff();


would it 'doStuff' for 7, 5, and 8?

or no?[/I]
 

Mr. Trivel

Praised Adventurer
Xy$
0.00
.split(' ') is for Strings, not arrays.
Why not just do
JavaScript:
var acva = [1, 7,5, 7];
for (var i = 0; i < acva.length; i++)
{
   if (acva[i] <= 2) this.doStuff();
}
 

clark

Villager
Xy$
0.00
actually, I was trying to learn to define a variable related to an actor from your perkpoints script, and i saw this:

var paramPPOL = String(parameters['Points On Levels'] || "1 3 5 7 10 13 14 15 18 20 25 30 35 40 45 50 55 65 75 85 90 93 96 98 99"); var paramPPOLD = paramPPOL.split(" ");

then this:


Game_Actor.prototype.initPerkPoints = function() {
for (var i = 0; i < paramPPOLD.length; i++) {
if (Number(paramPPOLD) <= this._level)
this.addPerkPoint();
};
};

but honestly, I'm just trying to set the initial variable to 0 except in certain conditions.... actors with id 1 and 2 will start with 5 points in these variables... funny how I'm learning from your script and you answered lol

see, I'm making 'invisible'-ish stats related to characters and I really just need to define the variables related to actors and be able to alter them with script calls... which, if I can understand this, I'm sure I can do it.

[doublepost=1458074640,1458074558][/doublepost]i assume that its checking the 'level' of the character, versus the levels defined as perkpoint levels, and adding points for each level defined as a perkpoint level - correct?
 

Mr. Trivel

Praised Adventurer
Xy$
0.00
That initPerkPoints is ran once when actor is first initialized to catch up on all perk points if he didn't start at level 1.
So I split that long number line into array and loop through it checking it against current actor level, if check passes - add perk point.

As for actor IDs, you could just do:
var theseIdsOnly = [1, 2];
if (theseIdsOnly.include(this._actorId))
{
this.doSomethingSpecial();
}
 
Last edited:

clark

Villager
Xy$
0.00
Alright, so if I add

var _GameActor_initMembers = Game_Actor.prototype.initMembers;
Game_Actor.prototype.initMembers = function() {
_GameActor_initMembers.call(this);
this._perkPoints = 1;

then the variable actor._perkpoints exists for all actors, at 1 point?
 

clark

Villager
Xy$
0.00
say i made an array of strings, if i used the

for (var i = 0 ; var i > array.lenth; i++)

and wanted to add

this._ before each string, how could this be accomplished?

say the array is

echo, bravo, alpha

and i want it to add

this._echo
this._ bravo
etc

the end results would be

this._echo = 0;
 

Kit Ramos

Villager
Xy$
0.00
first off I'd like to make mention that adding stuff on to strings will not change the location of the variable or the means to reference it but the contents of the variable,

so if you had such an array like:
Code:
var myarray = new Array("echo","bravo","alpha");
you could do something like this:
Code:
for(var i=0;i<myarray.length;i++)
{
    myarray[0]="this._"+myarray[I];
}

it will of added in the "this._" in front, making the this._echo you said you wanted but you wouldn't be able to refer to the variable using
this._echo= anything;​
because this._echo is not the variable name, but rather the contents of the variable:
Code:
myarray[0]
I don't think there's a dynamic way to create new variables, with out using something dangerous like eval()
but I could be wrong.
 
Last edited:
Top