[12 Dec 2009] Possible Bug in Designer plus a if vs switch question.

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

[12 Dec 2009] Possible Bug in Designer plus a if vs switch question.

Post by Bugala »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sat, 12 Dec 2009 22:56:26 -0000

a link to whd file in concern: http://dl.dropbox.com/u/3375468/Wandering%20tribe.hwd

and in case someone else is looking for handy way to share files publicly and privately too:

https://www.dropbox.com/referrals/NTMzNzU0Njg5

use this referral link to join for free, and both me and you will receive extra 250 Mb storage space.

If you open that Designer file, and go to "Final Question" - page.

Choose from there "Rec - Done" layer, and choose its "On click" menu, from there go to "custom code" and you will find:

Code: Select all

if RA>6 then %>5
if RA<7 then %>8
or something similar.

However, only first line works.

Idea is, that if there are too few answers (less than 7) right, then it would send you to "game over". If you get more than 6 right, it sends you to "game completed".

But only the top one works.

I also tried to do ti with structure of

Code: Select all

if RA>6
   %>5
elseif RA<7 
   %>8
endif
but that didnt work either.

1. So am i doing something wrong in here, or is there a bug in designer?

Second question is about Hollywoods compiled file.

One bit guru programmer once told me that i should use "switch" rather than "if".

That when "if" is used, it goes and looks through every "if" line, so if theres 100 "if" lines, it needs to go through them all.

But on the other hand switch simply creates pointer where it jumps depending on situation.

So in case of 100 "if" lines checked, it just looks the switch and jumps to right place right away.

2. So does Hollywood work this way too?

Im just asking so that if it is so, i start right from beginning using switches instead of sticking to my bad habbit of only using "if"s.
User avatar
TheMartian
Posts: 109
Joined: Sun Feb 28, 2010 12:51 pm

[13 Dec 2009] Re: Possible Bug in Designer plus a if vs switch question.

Post by TheMartian »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sun, 13 Dec 2009 19:01:47 -0000

Hi

Assuming that each action taken for a specific value can be written as a function it is much faster to take advantage of Hollywoods ability to have functions as variables. Particularly with many test values.

Imagine you have a table called MyAction and put three functions inside it with index 1, 0 and 2 and your three test values are 0, 1 or 2. Then there will be no jumping around. Just a call directly to the relevant function...

Code: Select all

MyAction={}
MyAction[0]=function some-code endfunction
MyAction[1]=function some-code endfunction
MyAction[2]=function some-code endfunction
This can be adapted to any test value because you can use strings as well as numbers as an index in a table.

In the case example you would simply call the function with the test value. If the test value was stored in the variable answer you would call the function

Code: Select all

MyAction[answer]
and the right function would be executed.

PS. Switch gets slower if the trigger value is a long way down in Hollywood as far as I can see.

regards Jesper
User avatar
TheMartian
Posts: 109
Joined: Sun Feb 28, 2010 12:51 pm

[13 Dec 2009] Re: Possible Bug in Designer plus a if vs switch question.

Post by TheMartian »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sun, 13 Dec 2009 19:16:59 -0000

Hi

Instead of lots of if's or a switch statement it is much faster to take advantage of Hollywoods ability to have functions as members of a list. Especially if you have lots of possible test values.

This assumes that your actions can be wrapped up in a function, which they probably can.

Imagine you have three test values 0,3,4, and the relevant one is stored in a variable called answer.

Now create a table called, say, MyFunctions.

Code: Select all

MyFunctions={}
MyFunctions[0]=function some-code endfunction
MyFunctions[3]=function some-code endfunction
MyFunctions[4]=function some-code endfunction
All you have to do is call:

Code: Select all

MyFunctions[answer]
to execute the right code.

This works too if your test values are strings or even a mixture of strings and numbers, since Hollywood supports string values as indexes.

PS. The switch statement gets slower as you traverse it if the correct answer is near the bottom as far as I can see.

PPS- I may have mailed a similar anwser a little earlier today. But something went 'POOF' just as I was about to mail it, so I have rewritten it in a somewhat different form.

regards Jesper
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[14 Dec 2009] Re: Possible Bug in Designer plus a if vs switch question.

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 14 Dec 2009 17:58:16 +0100
a link to whd file in concern: http://dl.dropbox.com/u/3375468/Wandering%20tribe.hwd

and in case someone else is looking for handy way to share files publicly and privately too:

https://www.dropbox.com/referrals/NTMzNzU0Njg5

use this referral link to join for free, and both me and you will receive extra 250 Mb storage space.

If you open that Designer file, and go to "Final Question" - page.

Choose from there "Rec - Done" layer, and choose its "On click" menu, from there go to "custom code" and you will find:

Code: Select all

if RA>6 then %>5
if RA<7 then %>8
This won't work because you're using the Short If statement. You should be doing it like this:

Code: Select all

If RA > 6   ; more than 6 right answers
  %>5    ; go to completed
Else
  %>8    ; else go to game over
EndIf
or something similar.

However, only first line works.

Idea is, that if there are too few answers (less than 7) right, then it would send you to "game over". If you get more than 6 right, it sends you to "game completed".

But only the top one works.

I also tried to do ti with structure of

Code: Select all

if RA>6
  %>5
elseif RA<7 
  %>8
endif
but that didnt work either.

1. So am i doing something wrong in here, or is there a bug in designer?

Second question is about Hollywoods compiled file.

One bit guru programmer once told me that i should use "switch" rather than "if".

That when "if" is used, it goes and looks through every "if" line, so if theres 100 "if" lines, it needs to go through them all.

But on the other hand switch simply creates pointer where it jumps depending on situation.

So in case of 100 "if" lines checked, it just looks the switch and jumps to right place right away.

2. So does Hollywood work this way too?

Im just asking so that if it is so, i start right from beginning using switches instead of sticking to my bad habbit of only using "if"s.
Do it as you like. Don't forget that Hollywood is a script language anyway so we're not battling for every CPU cycle here :)
Locked