Author Topic: Problem with Inline Conditions  (Read 4633 times)

Offline MT DNA

  • Bot Neophyte
  • *
  • Posts: 2
    • View Profile
Problem with Inline Conditions
« on: September 09, 2009, 02:15:07 AM »
Here is my code, I have removed everything that doesn't actually pertain to my question to make it more simple to read.
Code: [Select]
cond
 true
 'Condition for reproduction
start
  *.nrg 500 > mult 10 dropbool
  *.nrg 1000 > mult 20 dropbool
  *.nrg 4000 > mult 30 dropbool
  *.nrg 8000 > mult 40 dropbool
  .repro store
  .preg inc
stop

Ok now to confirm how I thought it worked. Correct me when I'm wrong (because I must be, 'cause my codes not working)

Cond must be true for any of the DNA from start to stop to execute.
nrg > 500 (true) add 10 to the stack (either way) drop the previous value from the bool stack putting it back to true.
nrg > 500 (true) add 20 to the stack (either way) drop the previous value from the bool stack putting it back to true.
nrg > 500 (true) add 30 to the stack (either way) drop the previous value from the bool stack putting it back to true.
nrg > 500 (true) add 40 to the stack (either way) drop the previous value from the bool stack putting it back to true.
(implied to be true) .repro store .preg inc

The way I've interpreted this is, that my values should only be added to the number stack if true is on the top of the bool stack, but I'm guessing I'm wrong on that. Obviously number have to be able to get on the stack in order for 2 1 > to be evaluated when false is on the stack. However, if thats the case how do I do this and make it right with only one store. I've been trying to keep my code a small and efficient as possible.

Thanks MT
« Last Edit: December 22, 2011, 12:07:42 PM by Shasta »

Offline abyaly

  • Bot Destroyer
  • ***
  • Posts: 363
    • View Profile
Problem with Inline Conditions
« Reply #1 on: September 09, 2009, 08:21:29 AM »
Your inline conditions are commented out.

Also, I think they control store, inc, and dec. Not every value push.
« Last Edit: September 09, 2009, 08:28:23 AM by abyaly »
Lancre operated on the feudal system, which was to say, everyone feuded all
the time and handed on the fight to their descendants.
        -- (Terry Pratchett, Carpe Jugulum)

Offline Shasta

  • Administrator
  • Bot Destroyer
  • *****
  • Posts: 231
    • View Profile
Problem with Inline Conditions
« Reply #2 on: September 09, 2009, 05:58:07 PM »
Quote from: MT DNA
Cond must be true for any of the DNA from start to stop to execute.
This is not quite true, conditionals will always be evaluated, regardless of the boolean stack. This is what I would do to achieve the same result:
Code: [Select]
start
    *.nrg 500 >
        10
    *.nrg 1000 >
        20
    *.nrg 4000 >
        30
    *.nrg 8000 >
        40
    true
    .repro store
stop


Offline MT DNA

  • Bot Neophyte
  • *
  • Posts: 2
    • View Profile
Problem with Inline Conditions
« Reply #3 on: September 10, 2009, 03:23:32 AM »
Quote from: Shasta
Quote from: MT DNA
Cond must be true for any of the DNA from start to stop to execute.
This is not quite true, conditionals will always be evaluated, regardless of the boolean stack. This is what I would do to achieve the same result:
Code: [Select]
start
    *.nrg 500 >
        10
    *.nrg 1000 >
        20
    *.nrg 4000 >
        30
    *.nrg 8000 >
        40
    true
    .repro store
stop

No the problem is whether or not the conditions are true the values get pushed onto the stack, I think maybe, I'm just going to go with something like

*.nrg 500 >
     *.nrg 5000 ceil 100 div

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Problem with Inline Conditions
« Reply #4 on: September 10, 2009, 03:49:25 PM »
I'm pretty sure that the values are pushed onto the stack regardless of the boolean stack.  Otherwise new conditions couldn't be evaluated.  The boolean stack only affects things like inc, dec, and store.  If the boolean stack is false, they still take values from the integer stack but nothing gets written to memory.