2ndwolf
September 29, 2012, 2:31pm
1
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;}
hosler
September 29, 2012, 2:38pm
4
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?
2ndwolf
September 29, 2012, 2:42pm
5
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!
I wasn’t aware I could concatenate strings that way
tricxta
September 29, 2012, 4:45pm
6
[QUOTE=2ndwolf;97481]
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!
I wasn’t aware I could concatenate strings that way
[/QUOTE]
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.
2ndwolf
September 29, 2012, 5:47pm
7
You can’t tokenize tokens though
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.
tricxta
September 29, 2012, 5:52pm
8
[QUOTE=2ndwolf;97489]
You can’t tokenize tokens though
Neither use a for in another for without lag.
[/QUOTE]
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.
2ndwolf
September 29, 2012, 5:57pm
9
Viva my 1.5ghz 1goRAM computer lol.
brooh you copied pasted that shiet.