Opening but closing works 25% of the time?

Considering this script… I don’t know, should work right?

if(timeout){
  get_Mkey();
  if(this.mkey==1&&this.fired!=1){
    this.fired = 1;
  }
  else if(this.mkey==1){
    playerdir = 2;
    close();
  }

  timeout = .05;
  if(this.fired==1){ 
   //do stuff
  }
}

function get_Mkey(){
  if(keydown2(keycode(m),true)){
    this.mkey = (this.mkey == 0)?1:2;//1 = pressed,2 = held
  }
  else{
    this.mkey = (this.mkey>0)?-1:0;
  }
}

function close(){
this.fired = 0;
}

The previous working, the problem is elsewhere:

[CODE]if(playerenters){
toweapons -worldmap;
disablemap;
timeout = .05;}

if(playerdies){
close();
}
if(playerhurt&&this.fired==1){
this.playerregen = 1
}

if(timeout){
get_Mkey();
if(this.mkey==1&&this.fired!=1){
setstring this.img,mapcontour.png;
setstring this.map,graalmap.png;
this.mapsize = {669,603}
setstring this.objectives,
“The prince”,294,39, //0
“Middle sorcerer’s place”,147,207, //1
“The farm”,359,141, //2
“Oompa Loompa village”,615,183, //3
“Elfic Library”,494,464, //4
“Elfic factory”,425,506, //5
“Elfic wedding”,450,568, //6
“Undergrapefruit farm”,308,367, //7
“Brave island”,414,240; //8
setarray this.key,10;
this.fired = 1;
freezeplayer .05;
timeout = .05;
setani maps1,;
this.scrollspeed = 4;
this.screenwidth=600;
this.screenheight=400;
this.windowSize = {int(min(screenwidth,this.screenwidth)/16)*16,int(min(screenheight,this.screenheight)/16)*16};
this.wPos = {(screenwidth-this.windowSize[0])/2,(screenheight-this.windowSize[1])/2};
this.stmapx = 96;
this.stmapy = 0;
drawBack();
drawmap();
sleep .25;
}
else if(this.mkey==1){
playerdir = 2;
close();
}

timeout = .05;
if(this.fired==1){
get_Keys();
freezeplayer .05;
setani maps2,;
if(this.playerregen==1){
setani maps2,;
playerhearts += playerhurtdpower;
playerhurtdx = 0;
playerhurtdy = 0;
this.playerregen = 0;
}
if(this.key[0]==2&&this.stmapy>0){
this.stmapy -= this.scrollspeed;
drawmap();
}
if(this.key[1]==2&&this.stmapx>0){
this.stmapx -= this.scrollspeed;
drawmap();
}
if(this.key[2]==2&&this.stmapy<this.mapsize[1]-this.windowSize[1]+18){
this.stmapy += this.scrollspeed;
drawmap();
}
if(this.key[3]==2&&this.stmapx<this.mapsize[0]-this.windowSize[0]+18){
this.stmapx += this.scrollspeed;
drawmap();
}
}
}

function drawBack(){
this.imgCount = 0;
for (this.wh = 0; this.wh < this.windowSize[0]*this.windowSize[1]/16;this.wh+=16){
showimg 301+this.imgCount,#s(this.img),this.wPos[0]+(this.wh%this.windowSize[0]),this.wPos[1]+int(this.wh/this.windowSize[0])*16;
if (this.wh % this.windowSize[0] == 0){//left
if (this.wh == 0)this.iPos = {0,0};//top
else if (int(this.wh/this.windowSize[0]) == this.windowSize[1]/16-1)this.iPos = {0,32};//bottom
else this.iPos = {0,16};//middle
}
else if (this.wh % this.windowSize[0] == this.windowSize[0]-16){//right
if (int(this.wh/this.windowSize[0]) == 0)this.iPos = {32,0};//top
else if (int(this.wh/this.windowSize[0]) == this.windowSize[1]/16-1)this.iPos = {32,32};//bottom
else this.iPos = {32,16};//middle
}
else if (int(this.wh/this.windowSize[0]) == 0){//top
this.iPos = {16,0};
}
else if (int(this.wh/this.windowSize[0]) == this.windowSize[1]/16-1){//bottom
this.iPos = {16,32};
}
else this.iPos = {16,16};
changeimgpart 301+this.imgCount,this.iPos[0],this.iPos[1],16,16;
changeimgvis 301+this.imgCount,5;
this.imgCount++;
}
}

function get_Mkey(){
if(keydown2(keycode(m),true)){
this.mkey = (this.mkey == 0)?1:2;//1 = pressed,2 = held
}
else{
this.mkey = (this.mkey>0)?-1:0;
}
}

function get_Keys(){
for (this.keyCheck = 0;this.keyCheck < 10; this.keyCheck++){
if (keydown(this.keyCheck))
this.key[this.keyCheck] = (this.key[this.keyCheck] == 0)?1:2;//1 = pressed,2 = held
else
this.key[this.keyCheck] = (this.key[this.keyCheck]>0)?-1:0;//-1 = released, 0 = not held
}
}

function close(){
hideimgs 301,311+this.imgCount;
hideimg 300;
this.fired = 0;
}

function drawmap(){
showimg 300,#s(this.map),this.wPos[0]+11,this.wPos[1]+11;
changeimgpart 300,this.stmapx,this.stmapy,this.windowSize[0]-22,this.windowSize[1]-22;
changeimgvis 300,4;
}[/CODE]

Often, fired is = 0 yet the map stays open…
and right now this.mkey is invariably = 1…
or fired = 1 yet the player is not frozen…

This makes me think of the time the only thing I added was keydown2(keycode©,true) to a condition on my dash boots and my character started running diagonally.

wtf Really

I suppose you could do something like

if (keypressed){
  if (strtofloat(#p(0)) == keycode(m)){
    while (keydown2(keycode(m),true))sleep 0.05;
    this.fired = (this.fired+1)%2;

    if (this.fired == 1){
      timeout = 0.05;
    }
    else {
      close();
    }
  }
}

That’s a bit of cheats way of doing it though.

…still refuses to close… :’(

[CODE]if(playerenters){
toweapons -worldmap;
disablemap;
}

if(playerdies){
close();
}
if(playerhurt&&this.fired==1){
this.playerregen = 1
}

if (keypressed){
if (strtofloat(#p(0)) == keycode(m)){
while (keydown2(keycode(m),true))sleep 0.05;
this.fired = (this.fired+1)%2;
if (this.fired == 1){
timeout = 0.05;
}
else {
close();
return;
}
}
}

if(timeout){
if(this.init==0){
setstring this.img,mapcontour.png;
setstring this.map,graalmap.png;
this.mapsize = {669,603}
setstring this.objectives,
“The prince”,294,39, //0
“Middle sorcerer’s place”,147,207, //1
“The farm”,359,141, //2
“Oompa Loompa village”,615,183, //3
“Elfic Library”,494,464, //4
“Elfic factory”,425,506, //5
“Elfic wedding”,450,568, //6
“Undergrapefruit farm”,308,367, //7
“Brave island”,414,240; //8
setarray this.key,10;
this.fired = 1;
freezeplayer .05;
timeout = .05;
setani maps1,;
this.scrollspeed = 4;
this.screenwidth=600;
this.screenheight=400;
this.windowSize = {int(min(screenwidth,this.screenwidth)/16)*16,int(min(screenheight,this.screenheight)/16)*16};
this.wPos = {(screenwidth-this.windowSize[0])/2,(screenheight-this.windowSize[1])/2};
this.stmapx = 96;
this.stmapy = 0;
drawBack();
drawmap();
this.init = 1;
}
get_Keys();
freezeplayer .05;
setani maps2,;
if(this.playerregen==1){
setani maps2,;
playerhearts += playerhurtdpower;
playerhurtdx = 0;
playerhurtdy = 0;
this.playerregen = 0;
}
if(this.key[0]==2&&this.stmapy>0){
this.stmapy -= this.scrollspeed;
drawmap();
}
if(this.key[1]==2&&this.stmapx>0){
this.stmapx -= this.scrollspeed;
drawmap();
}
if(this.key[2]==2&&this.stmapy<this.mapsize[1]-this.windowSize[1]+18){
this.stmapy += this.scrollspeed;
drawmap();
}
if(this.key[3]==2&&this.stmapx<this.mapsize[0]-this.windowSize[0]+18){
this.stmapx += this.scrollspeed;
drawmap();
}

timeout = .05;
}

function drawBack(){
this.imgCount = 0;
for (this.wh = 0; this.wh < this.windowSize[0]*this.windowSize[1]/16;this.wh+=16){
showimg 301+this.imgCount,#s(this.img),this.wPos[0]+(this.wh%this.windowSize[0]),this.wPos[1]+int(this.wh/this.windowSize[0])*16;
if (this.wh % this.windowSize[0] == 0){//left
if (this.wh == 0)this.iPos = {0,0};//top
else if (int(this.wh/this.windowSize[0]) == this.windowSize[1]/16-1)this.iPos = {0,32};//bottom
else this.iPos = {0,16};//middle
}
else if (this.wh % this.windowSize[0] == this.windowSize[0]-16){//right
if (int(this.wh/this.windowSize[0]) == 0)this.iPos = {32,0};//top
else if (int(this.wh/this.windowSize[0]) == this.windowSize[1]/16-1)this.iPos = {32,32};//bottom
else this.iPos = {32,16};//middle
}
else if (int(this.wh/this.windowSize[0]) == 0){//top
this.iPos = {16,0};
}
else if (int(this.wh/this.windowSize[0]) == this.windowSize[1]/16-1){//bottom
this.iPos = {16,32};
}
else this.iPos = {16,16};
changeimgpart 301+this.imgCount,this.iPos[0],this.iPos[1],16,16;
changeimgvis 301+this.imgCount,5;
this.imgCount++;
}
}

function get_Keys(){
for (this.keyCheck = 0;this.keyCheck < 10; this.keyCheck++){
if (keydown(this.keyCheck))
this.key[this.keyCheck] = (this.key[this.keyCheck] == 0)?1:2;//1 = pressed,2 = held
else
this.key[this.keyCheck] = (this.key[this.keyCheck]>0)?-1:0;//-1 = released, 0 = not held
}
}

function close(){
hideimgs 301,311+this.imgCount;
hideimg 300;
this.fired = 0;
this.init = 0;
}

function drawmap(){
showimg 300,#s(this.map),this.wPos[0]+11,this.wPos[1]+11;
changeimgpart 300,this.stmapx,this.stmapy,this.windowSize[0]-22,this.windowSize[1]-22;
changeimgvis 300,4;
}[/CODE]

I see you’re using my key function so you can do a much better method

if (playerenters){
  setarray this.key,10;
}

if (keypressed){
  get_Keys();
  if (this.key[7] == 1){
    this.fired = (this.fired + 1)%2;
    if (this.fired == 1){
      timeout = 0.05;
    }
    else {
      close();
      while (this.key[7] > 0){//kinda gross but it's needed if you don't want your open function bugging out
        get_Keys();
        sleep 0.05;
      }
    }
  }
}

if (timeout && this.fired == 1){
  get_Keys();  

  timeout = 0.05;
}

That’s all the help i’m giving, if you can’t work it out from there then you’re just out of your own depth.

Now it only stays closed if I keep the M key pressed.
In fact, the behavior is as buggy as before…

I… wont… give… up… X_X

this.key[7] is stuck at 2… this is unusual…

Ok now I need to keep m pressed for it to close, almost there… this is only because of lag, great I worked it out.