Human Resource Machine

Human Resource Machine

View Stats:
Flame Soulis Oct 17, 2015 @ 4:30am
Conditional Jump Help
Okay, I know I'm about to sound spoiled, but these jump statements just leave me staring in rage. I know it's mostly me not having worked on as low of a level of programming, but wrapping my head around them is just painful.

It isn't that I don't understand their uses, it's that I'm too used to the actions of conditions being within an actual bracketted statement. I am familar with normal jumps and do use them from time to time, but conditional jumps throw everything I've learned about conditional handling out the window (and considering I'm stuck on floor 20, it's a decent fall).

My question: is there some trick with conditional jumps that a programmer who mostly sticks to conditional statements can use better understand the more proper way of using conditional jumps?

Side Note: Most likely going to make it a seperate dicussion, but OH PLEASE GIVE US A FLOOR FOR EXPERIMENTING! Kinda like how you had the sandbox area in World of Goo, a sandbox for the programming commands you have learned would be stupid helpful. My reasoning is that I'm stuck on Floor 20 due to zeros, and having to wait for a zero to pop up for debug is PAINFUL. Yeah I can back step, but it'd be nice if I could expedite it.
< >
Showing 1-5 of 5 comments
Try using labels to add the silly string syntax back in: http://i.imgur.com/ubhwdUQ.jpg
KRAFTPANZER Oct 17, 2015 @ 5:25am 
My own level 20 resolution looks like a mess,I really have to work on it once I finished the game. My very unclever solution to the zeroes is checking in the 2 possible cases (the 2 numbers, let's call them x and y), directly after inbox, putting in that zero jump thing. If he did so, it skips to the very end of my code (I simply labelled it "if 0" to somewhat keep track of it), where, depending on whether it's the x he picked up, he will simply throw away the y via another inbox command (as the result will always be 0 anyway), and take that zero that's already in the middle there and put it to the outbox.

I have no idea if my description made enough sense. My solution has 23 steps, the short one should have 15, so it is not that great. However, if it's of any help for you, I can paste it in here.

Personally, I try to use labels when it gets more complex, as writing everything in one row can become messy. Especially those damn jumps can annoy the hell out of me.
Last edited by KRAFTPANZER; Oct 17, 2015 @ 5:26am
Flame Soulis Oct 17, 2015 @ 6:42am 
Okay... still trying to get used to things, but I kinda am getting it now. After seeing Wroz's answer for Floor 20, I began to understand more about the flow and the major differences in logic between conditional statements and conditional jumping. I'm not sure exactly how to describe it yet, but I do get it. It just boils down to keeping the flow of the program to almost always flor downward, where a jump shouldn't be used to skip ahead only to skip back whenever possible, which was how I was doing 'conditional statement' jumps.
KRAFTPANZER Oct 17, 2015 @ 6:47am 
It takes time getting used to it. I feel like too much background knowledge can it actually make more difficult, as you try to apply a soultion that won't worke with the game's logic. My three sort, for example, looked awful..
Excors Oct 17, 2015 @ 7:12am 
If you're familiar with normal structured programming in C/Java/Python/etc, I think it's helpful to first work out how you'd solve the problem using the normal control structures, and then work out how to translate those into low-level instructions.

You can use forward jumps to implement 'if' blocks:
if (!(acc < 0)) { // equivalent to "if (acc >= 0)" ... }
JUMPN a COMMENT 0 a: DEFINE COMMENT 0;
and if-else blocks:
if (!(acc < 0)) { ... } else { ... }
JUMPN a COMMENT 0 JUMP b a: COMMENT 1 b: DEFINE COMMENT 0; DEFINE COMMENT 1;

You can use backward jumps for do-while loops (i.e. where it's always going to execute the loop body at least once):
do { ... } while (acc < 0);
a: COMMENT 0 JUMPN a DEFINE COMMENT 0;

and combine with an unconditional jump to get a while loop:
while (acc < 0) { ... }
JUMP b a: COMMENT 0 b: JUMPN a DEFINE COMMENT 0;

or you can do one with the opposite condition:
while (!(acc < 0)) { // equivalent to "while (acc >= 0)" ... }
JUMPN b a: COMMENT 0 JUMP a b: DEFINE COMMENT 0;

You can build up more complex control flow from those basic ones - e.g. a 'for' loop is just a 'while' loop where you modify the condition variable before jumping back to the top. But to get the most efficient programs you might have to break out of those patterns and do something more convoluted.

(I think this makes it clear why high-level languages all have good support for structured control flow, and rely on a compiler to translate it all into the conditional jumps that the hardware understands. Given the theme of the game, it's kind of ironic that we have to do that translation manually here!)
< >
Showing 1-5 of 5 comments
Per page: 1530 50

Date Posted: Oct 17, 2015 @ 4:30am
Posts: 5