Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    43
    Thanks
    8
    Thanked 0 Times in 0 Posts

    One of two if statements execute

    edit:: got it to work setting inBooth to false in the function where I clear the menu, but then it's refreshing to div so often while you're standing in the booth (30 frames/sec, it's a game) that nothing happens when you click the buttons to buy/sell unless you click really really fast....

    anyone know a good way to check whether something is true, then toggle an innerHTML div, then once the value becomes false, toggle the innerHTML div to empty....??simply??


    But if I reverse the order the opposite works but then the other doesn't......

    Code:
    if (condition==true ) {
    generateSale();
    inBooth=true;
    smithShop();
    } else {inBooth=false;clearSale();}
      
     
    //IS PLAYER IN VENDOR BOOTH?
    if (condition2==true ) {
    generateSale();
    inBooth=true;
    vendorShop();
    } else {inBooth=false;clearSale();}
    Only the "generateSale()" from the second one executes. If I switch the if blocks, the second one with "generateSale()" executes.

    If I change "clearSale();" to a "setTimeout=('clearSale()',1000)" then both execute "generateSale()" but the div it affects flickers repeatedly as it's cleared/remade.

    generateSale() changes the innerHTML of a div, clearSale() just overwrites the innerHTML with ' '

    Code:
    var sales2;
    
    function clearSale() {
    	sales2=document.getElementById('sales2');
    	sales2.innerHTML='';
    	}
    
    function generateSale(){ 
    	 sales2=document.getElementById('sales2');
    	sales2.innerHTML=
    	'Buy/Sell:  '+'   Gold coins: '+playerInventory[lootArray[7]]+'<br>'
    	+'        Consumables:<br>'
    	
    	+'You have: '+playerItems[itemArray[4]] +' arrows<br>'
    	+'<input type="button" value="Buy" onclick="buyIt(0);">'+'10 for 50gp<br>'	
    	+'<input type="button" value="Sell" onclick="sellIt(0);">'+'10 for 25gp<br>'
    }

    Any ideas? Basically when my character enters the range of an image of a building I have a menu pop up saying you're in a vendor booth.

    I want it to run generateSale() which changes a div on the screen to list a bunch of stuff you can buy/sell. When your character is no longer standing in range, I want it to clear that information, so you have to be standing within range in order to trade items.

    Currently I can make it generates the sale menu, but it doesn't clear it when you leave the range. I've tried all kinds of "toggle" variables to set whether you're in range or not, but only the second block fires, not the first and I cannot figure out why...

    Any ideas? The code all works fine it just won't clear for all the different buildings, only one....
    Last edited by nuBee; 01-01-2012 at 05:19 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •