help with unit conversion parallel process

● ARCHIVED · READ-ONLY
Started by mike_your_bro 4 posts View original ↗
  1. Hello, I am currently working on a game and am in the need of a little help.

    What I'm trying to do is this:

    someone gives you 10 grams

    you get 10 grams

    gives you 20 grams (total 30)

    parallel process changes that to

    1 ounce and 2 grams

    And when you take away 3

    grams the same parallel process

    leaves you with 0 ounces and

    27 grams.

    It doesn't SOUND very

    complicated but believe me,

    unless I'm missing something

    obvious, it is.

    WHAT I HAVE SO FAR:

    6 variables

    -1- "Unit Conversion 1 - Ounce"

    -2- "Unit Conversion 2 - Gram"

    -3- "Total Grams"

    -4- "Unit Conversion Math

    Problem 1"

    -5- "Unit Conversion Math Problem 2"

    -6- "Random Number"

    4 events

    -1- Person that gives you grams

    control variable>set to

    random number between

    2 and 17

    text: Here's \V[6] grams.

    change items>add>by

    variable [6]

    -2- Person that wants grams

    control variable [6]>set to

    random number between

    2 and 27

    text: Can I have [6] grams

    choices: yes:

    conditional branch>if variable

    [3] is greater than or equal to

    variable [6]

    then: text: Thanks.

    control variable [2]> subtract

    by variable [6]

    else: text: Oh, Sorry.

    You don't have enough grams.

    no: Okay.

    -3- Person that tells you amount ('ounces' and 'grams', or 'total grams')

    choice: ounces AND grams

    text: You have [1] ounces and

    [2] grams.

    total grams

    You have [3] total grams

    -4- Parallel Process

    variable[1] set to [game

    data: number of ounces in

    inventory]

    variable[2] set to [game

    data: number of grams in

    inventory]

    conditional branch>

    variable[2] is greater than or

    equal to 28

    then: change items "Ounce"

    add 1

    change items "Gram"

    subtract 28

    set variable [1] to number

    of ounces in inventory

    set variable [2] to number

    of grams in inventory

    else:

    --

    variable [math 1] set to 28

    --

    variable [math 1] multiplied by

    [1](number of ounces)

    --

    variable [math 1] add [2]

    (number of grams)

    --

    variable [total grams] set to

    variable [math 1]

    --

    conditional branch: if [2] is less

    than 0, then :

    conditional branch: if [1]

    is greater than or equal to 1,

    then:

    variable [math 2] set to 28

    --

    variable [math 2] add [2](which

    will be negative when this runs)

    --

    change items: Ounce subtract 1

    --

    change items: Gram add by variable [math 2]

    --

    control variable [1] set to game

    data: number of Ounce

    --

    control variable [2] set to game

    data: number of Grams
  2. i know that might be very hard to follow, but it is as detailed as i could make it, i really want this to work, and i have been wracking my brain for WEEKS now over this. very tedious to make a whole system in a single event, and very painful to see it not work properly.

    here's the problem i am having:

    on my version, posted above, the person gives you for example, 30 grams. i talk to another person, and if i choose the first option, he says '"1 ounce and 2 grams."

    then i talk to a third person who takes 5 grams. if i talk to the second person again, he says "1 ounce and 0 grams."

    and for total he still says "30 grams."

    not sure quite what's going on here.
  3. I have to wonder why you're converting something to ounces AND grams, when they're from two completely different measurement systems. But anyway ... best way is to NOT convert at all for the purpose of keeping track. Use a single variable in the smallest unit of measure (grams) to keep track of how much you have. Do all the math in that unit of measure. Only do the conversion for the purpose of displaying how much you've got, or if they can give/take ounces as well as grams. You can use a common event to convert from ounces/grams to grams (to update how much you have), and another to convert from grams to ounces/grams to display how much you have. These will both use two temporary variables that will be calculated, then you have to do something with them (update grams, or display them) straight away. Ditch the parallel process, and just add a call to the common event whenever you update it (why have a parallel process to check something continually when it's only going to change on the odd occasion?)

    So ...

    Variable 1: Amount held (in grams)

    Common Event 1: Convert to ounces/grams

    Variable 2: Ounces = Variable 1 / 28

    Variable 3: Grams = Variable 1 - (Variable 2 * 28)

    Common Event 2: Convert to grams

    Variable 3: Grams = Variable 3 + (Variable 2 * 28)

    Event 1:

    Person gives you 0 ounces and 20 grams

    Variable 2: Ounces = 0

    Variable 3: Grams = 20

    Call Common Event: Convert to grams (variable 3 stays as 20)

    Variable 1: Amount Held = Variable 1 + Variable 3

    Event 2:

    Person gives you 1 ounce and 20 grams

    Variable 2: Ounces = 1

    Variable 3: Grams = 20

    Call Common Event: Convert to grams (variable 3 becomes 20 + 28 = 48)

    Variable 1: Amount Held = Variable 1 + Variable 3 (20 + 48 = 68)

    Event 3:

    Person tells you how much you have

    Call Common Event: Convert to ounces/grams (variable 2 becomes 2 [68/28 = 2r12]; variable 3 becomes 12)

    Display "You have \v[2] ounces and \v[3] grams" (sorry, I'm used to XP, and I know the way to show a variable has changed, but I can't remember how it works now)

    Event 4:

    Person takes away 15 grams

    Variable 2: Ounces = 0

    Variable 3: Grams = 15

    Call Common Event: Convert to grams (variable 3 is 15)

    Variable 1: Amount Held = Variable 1 - Variable 3 (68 - 15 = 53)

    Event 3:

    Person tells you how much you have

    Call Common Event: Convert to ounces/grams (variable 2 becomes 1 [53/28 = 1r25]; variable 3 becomes 25)

    Display ....

    If you only add and remove in grams, never ounces, then you don't need to worry about calling the common event to convert to grams - just change variable 1 appropriately.
  4. thank you and another thanks for the speedy comment, i will try what you suggested as soon as I'm back by the computer, and btw you still display the variable with \V[x]. And the reasoning to be honest is probably best left unsaid. thanks a ton, i'll comment back when I try it out.