Forum rules - please read before posting.

Handling Variables For A Simple "Shooter" Section

I'm trying to put short fps sections in this game, like in TellTale's Walking Dead Season 1.
General shooting mechanics I have working, but I'm a little unsure on handling reloading with variables.
Variables I have are:
"Loaded_ammo" - the ammo in the magazine.
"Reserve _ammo" - backup ammo not yet loaded.

Say I have a gun that holds 10 bullets, and I have a reload button set up using an active input.
When I press reload, it would deduct 10 from "Reserve_ammo" and add 10 to "Loaded_ammo" this is fairly simple. However, what should I do when "Reserve_ammo" is less than 10?
I need to somehow check if "Reserve_ ammo" is less than 10, then add whatever is left to "Loaded_ammo".

This last part I am stuck on, any help appreciated.

Comments

  • Purely done through the standard Actions, I suppose you could do it by deducting 10 as normal, and then adding on the value of "Reserve_ammo" if it's negative.

    Say it's 7 to begin with. Upon reloading, "Loaded" and "Reserve" are then 10 and -3 respectively. "Reserve" is now negative, so "Loaded" gets -3 added to it which becomes 7.

    Though, it's also possible to read and manipulate variables through script - see the front page of the Scripting Guide.

  • Excellent! Thank you.

  • Coming back to this, I think it could be done on smaller action lists using a simple formula. Your tutorial here was very helpful in giving me a head start.

    So if loaded is [var:1]
    and reserve is [var:2]

    You can check if loaded is less than 10, then check if the value of reserve is less than 10, and if it is, by using the formula: [var:1]=[var:2], and so whatever is left in reserve is what is added to loaded.

    However, if reserve is not less than 10, I need to somehow find the value of how much space is left in the magazine, which means I need to introduce another variable, eg. max_clip. Do another formula maybe? [var:3]-[var:1] (to find out how much space is remaining) then subtract that from [var:2] and add it to [var:1] (or just set it to 10).

    I may have mixed those up a little, I may also be overthinking it. It seemed clear when I first started on it, hehe.

  • edited September 2019

    I've sorted the first part. It actually required 4 variables in the end:
    Loaded, Reserve, Max_Clip and Bullets_To_Load.

    All done by just one check (to see if reserve is less than bullets to load) and then three formulae.

    Now I just need to figure out how to deduct from reserve even if it's less than bullets to load but more than empty (0).

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.