Author Topic: What's an operand?  (Read 11257 times)

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
What's an operand?
« on: 2008-01-27, 06:30:37 PM »
Can someone tell me what this"operand" term you university students speak of and what does it do?

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: What's an operand?
« Reply #1 on: 2008-01-27, 07:34:44 PM »
An operand is one of two parts of an operation.

An operation, for example, is 4+5.  Here, the operands are 4 and 5, while the operator is +.  The operator is what happens to ("operates on") the operands.

A similar word relation in the English language (though not the same) would be employee and employer.  The employer is the one who employs the employee.  The operator is what operates on the operand or operands.  I say "operand or operands" here because there are unary (single-operand operations), binary (two-operand operations), ternary (three-operand operations) and combinations of operators which yield something like x=4+5.  You have the 4+5 operation, which results in 9, then you have the x=9 operation, which results in assigning the value of 9 to the variable x.
Edward Dassmesser

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: What's an operand?
« Reply #2 on: 2008-01-28, 06:44:10 AM »
How does this fit with SGDK2? ??? ??? ??? ??? ??? ???

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: What's an operand?
« Reply #3 on: 2008-01-28, 07:50:58 AM »
In SGDK2, if you pick an operator (such as "+" or "=") as your function for a rule, then the parameters are labeled "left operand" and "right operand".  So if you pick "+" as the function, and provide "x" as the value for left operand and "1" as the value for right operand, that results in the expression
x+1
Then if you put x as the value for "output to", that means that the result will be put back into x yielding a statement like this:
x = x + 1.

The result would be (assuming this is a sprite rule) the sprite would move to the right one pixel.

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: What's an operand?
« Reply #4 on: 2008-02-01, 09:22:42 PM »
Thanks Man. Looks like someone paid attention in his childhood math classes! So that rule you said...
Quote
The result would be (assuming this is a sprite rule) the sprite would move to the right one pixel
Is that how to move a sprite with the rule" If right is pressed"?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: What's an operand?
« Reply #5 on: 2008-02-02, 10:22:10 AM »
That's not the recommended way to move sprites because it doesn't account for reacting to solidity on the map.  The recommended way of moving a sprite is to map all the player inputs to the sprite inputs at once with MapPlayerToInputs.  Then call AcceleratyByInputs to affect the sprite's velocity (dx and dy) based on which inputs are pressed.  Then call ReactToSolid to make sure the sprite won't be moving into any solid ground.  Then call MoveByVelocity to make the sprite actually move.  This accomplishes a lot with just a few rules.  That way you don't have to have separate rules for each direction and such (though you still have that option if you're doing something complicated).

Jam0864

  • Contributor
  • Fanatic
  • **
  • Posts: 744
    • MSN Messenger - marmalade0864@hotmail.com
    • View Profile
    • Jam0864's Content Dump
    • Email
Re: What's an operand?
« Reply #6 on: 2008-02-02, 06:06:17 PM »
don't worry, it makes a lot more sense if you follow the tutorial.

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: What's an operand?
« Reply #7 on: 2008-02-08, 06:54:32 AM »
Thanks, but I'm starting to understand SGDK now. I made a simple left-right sprite. Never again now shall I use 1.x anymore. :educated: