This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-05-18 17:26:44

estorken
Scratcher
Registered: 2010-04-01
Posts: 41

formula vs if

so, if you to modify a variable, go to {x, y} or find an item in a list, but you want a different number depending on a variable there are two ways i know of. you can use if else, or a formula. which one is better? if can be easier, but do they run slower? i normally try to use formulas, but are they really better? thanks, i appreciate the help


http://i56.tinypic.com/esqpma.gif

Offline

 

#2 2011-05-19 07:58:12

Pecola1
Scratcher
Registered: 2010-09-06
Posts: 1000+

Re: formula vs if

estorken wrote:

so, if you to modify a variable, go to {x, y} or find an item in a list, but you want a different number depending on a variable there are two ways i know of. you can use if else, or a formula. which one is better? if can be easier, but do they run slower? i normally try to use formulas, but are they really better? thanks, i appreciate the help

I don't quite get what your asking. If I am correct, you want to make a variable which will set, depending on what the variable is already set to? I don't think thats it, can you explain?


If you are reading this, please read to the end, because if you don't you won't know what's at the end. Don't just skip to the end though otherwise you won't be able to read the middle, which is most important. Now you must be wondering why you just read all that, the reason is you may have not noticed something, read it again and see if you notice it this time  smile

Offline

 

#3 2011-05-19 12:08:28

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: formula vs if

It really depends on the purpose.

Generally, I prefer using formulae for my work. They give smoother results, take up a lot less blocks and run 100 times faster.

However, IF blocks are much more useful if you need to test for booleans which don't give usable numbers.

To pick from a list, to set the position of a sprite or other purposes which involve more than 3 possible values, formulae are easier and better.

Last edited by LS97 (2011-05-19 12:08:46)

Offline

 

#4 2011-05-20 19:12:08

estorken
Scratcher
Registered: 2010-04-01
Posts: 41

Re: formula vs if

thank you very much LS97.

Pecola1 you do seem confused, so here is an example.

if(start = 1)
{
     goto (25,50)
}
else
{
    if (start =2)
    {
        goto (75, 80)
    }
}


OR
goto ((start * 50)-25,20 + (start * 30))


http://i56.tinypic.com/esqpma.gif

Offline

 

Board footer