HUD Key quantity

Cuz a good dungeon is a dungeon with keys.

// NPC made by 2ndwolf
if (created) {
  toweapons -keycounter;
  timeout =1;
}

function keyrightdigits(){
  this.number = strtofloat(#s(playerkeys));
  this.digit = this.number-(int(this.number/10)*10);
  this.x = 432;
  this.y = 49;


  for (this.i=0; this.i<10; this.i++) {
    if(this.digit == this.i){showimg 1001,hud#v(this.i).png,this.x,this.y;}
  }

  changeimgvis 1001,4;
}

function keyleftdigits(){
  this.number = strtofloat(#s(playerkeys));
  this.digit = int(this.number/10);
  this.x = 420;
  this.y = 49;


  for (this.i=0; this.i<10; this.i++) {
    if(this.digit == this.i){showimg 1002,hud#v(this.i).png,this.x,this.y;}
  }

  changeimgvis 1002,4;
}

if (timeout){
  showimg 1000,hudkey.png,425,27;
  changeimgvis 1000,4;

  keyrightdigits();
  keyleftdigits();

  timereverywhere;
  timeout = 1;
}

And the key script:

if(created){
setshape 1,16,16;
}
if(playertouchsme){
setstring playerkeys,#v(strtofloat(#s(playerkeys))+1);
destroy;}

More numbers

And a nine

for (this.i=0; this.i<10; this.i++) {
if(this.digit == this.i){showimg 1002,hud#v(this.i).png,this.x,this.y;}
}

would this work instead of using all those if statements?

A for loop could reduce the quantity of ifs but that wouldn’t be the right way to do it…

EDIT:
In fact, yeah, that’s exactly how to do it! :smiley:
I wasn’t aware I could concatenate strings that way :open_mouth:

Yer gs1 is nice like that. You can even nest strings inside strings to define strings.

setstring test#v(random(0,10)),#I(testarray#v(int(random(0,2)),int(random(0,10)));

One of the things I like most about gs1 hah.

You can’t tokenize tokens though :frowning:
Neither use a for in another for without lag.

What I like about gs1 is that any non declared variable is automatically = 0.
That’s nice.

You can tokenize tokens but that’s weird and silly.
As for the for loop, it all depends on your processor as to how much computations you can take at a time.

Viva my 1.5ghz 1goRAM computer lol.

glad i helped

brooh you copied pasted that shiet.