Need help with Basic Maths!

0 favourites
  • 12 posts
From the Asset Store
Here is the wonderful & amazing script for your website or fun with maths.
  • Hi guys, so I'm making a game similar to what dope wars what, but this is aimed for everyone. However i've run into a road block. I'm not the great at putting things into words but here's what I'm after.

    I have an XY array with Product - Min Price - Max Price. It works fine and randomizes between Min Price & Max price.

    Here's what I'm trying to do (all input is welcome)

    I want it so that the user can purchase X amount of a product with their wallet. Problem is the wallet goes into minus numbers.

    I also need it to work in such a way that if a user doesnt have the money, he cant buy a product and in reverse, if he doesnt have the products, he cant sell the stock.

    Can anyone show me the best way or atleast point me in the right direction?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This just seems very easy to do but we don't know how your game works. You would just check if the player money is greater than the product price before purchasing and if not then disable purchase. For the selling I would add product amount to the array (unless product is product amount and not product name) and then say if that value is 0 then you cannot sell.

  • How would I go about disabling it? I know that must be a very silly question. I only started last night. I know how to make things run but have no idea about conditions. I know a little PHP and if i were using that an If / Else would do the job.

  • Do you have a purchase mechanic? How does it work currently? You said you saw the wallet go into negative value so that implies there is a purchase mechanic already and you tried something. In the general sense you are looking to use conditions, which are kind of like 'if statements' for construct. When you say in a condition 'player money greater than product price', it will only run the actions, a purchase in this case, if that is true.

  • Hi mate so I gave it a bash with what you said above so this is how I've gone about it and the trouble I'm facing.

    As the player hits start, the wallet starts with 2k. Then if the value of the product is less than the wallet money it becomes available for purchase. I'm trying to disable the increase quantity button when the quantity * the product value exceeds the wallet money.

    It only half does it so for example

    If wallet money < product value = increase quantity button disable

    If wallet money > product value = button enables and add's one to the quantity instance variable.

    The problem I'm facing now is that given the image below, it allows me increase the quantity to two, when i want to disable it because there isnt enough wallet money to purchase 2 * product value.

    How would I go about rectifying this?

    Thanks!

  • I can't see an image but I guess what you need is to check If wallet money < product value * quantity.

  • Hi Plinkie, I managed to get it figured out I think. So far everythings working as expected. I think I just did too much and overthought it and your first reply to the post brought me back to reality :) You've been a massive help!

  • Probably something like the following. Only considering one product but it’s basically the same for multiple.

    Global number wallet=5000
    Global number applePrice=45
    Global number applesOwned=0
    Global number quantityToTrade=10
    
    Wallet < applePrice*quantityToTrade
    — disable buy button
    Else
    — enable buy button
    
    On buy button pressed
    — add quantityToTrade to applesOwned
    — subtract applePrice*quantityToTrade from wallet
    
    quantityToTrade > applesOwned
    — disable sell button
    Else
    — enable sell button
    
    On sell button pressed
    — subtract quantityToTrade from applesOwned
    — add quantityToTrade*applePrice to wallet
  • Rojo what you've posted works very well with a hell of a lot more clinical methods than what I used. My only question now is, how do I avoid minus numbers when buying?

    http://i66.tinypic.com/jl6m44.jpg[/img]

    Any pointers would be great

  • Yep that looks fine, are you saying that it's working now or do you need some help?

  • It works, I just need a little help. when i increase the quantity of what i want to purchase or sell, it will let me buy more than what my wallet would allow me and send me in to minus numbers.

  • you could try to clamp the wallet value.

    in the actions set the following

    clamp(wallet, minimumvalue, maximumvalue)

    i.e. clamp(wallet,0,99999999)

    what this will do is stop the wallet from getting smaller than the min val defined and getting larger than max value defined, hope this helps you.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)