Questions Regarding Hollywood

Find quick help here to get you started with Hollywood
Bugala
Posts: 823
Joined: Sun Feb 14, 2010 7:11 pm

Re: Questions Regarding Hollywood

Post by Bugala » Mon Jul 01, 2019 4:34 pm

Here is the Scrolltext you are looking for, I will explain you how this works.

First of all, you need to make 3 "actions" to your script.

First Script is following:

Code: Select all

screenwidth = 640

scrollspeed = 100
y = 200

SetFont(#SANS, 50)

CreateTextObject(1, "my text to scroll", {color=#BLUE})

WidthOfText = GetAttribute(#TEXTOBJECT, 1, #ATTRWIDTH)
x = 50 + screenwidth

StartTimer(1)



continuescrollloop=False
Repeat
	
	timerloopcontinue = False
	Repeat
		timepassed = GetTimer(1)
		If timepassed => 5 Then timerloopcontinue = True
	Until timerloopcontinue=True

ResetTimer(1)
x=x - (100 * (timepassed/1000))
If x < -50 - widthoftext Then x = 50 + screenwidth
ShowLayer("scrolltext", x, y)

Until continuescrollloop=True



RemoveLayer("scrolltext")
I will now explain you what is happening here. You dont need to understand everything, only some things where you need to change numbers possibly.

First line is setting Screenwidth. This is important to be right, or scrolling will start/end at wrong locations. Idea is that if you are using for example 1920x1080 display (HD resolution) then you will mark Screenwidth as 1920.

You can try putting your page to 1920x1080 and yet use screenwidth of only 640. Especially if text amount to scroll is small amount. you might actually undertand this code better when you see it working wrong.


Next three lines are up to you to put how ever you like.
Speed is the scrolling speed. This speed refers to amount of pixels it will move in one second.

y refers to where in up-down sense will the screen display. 0 will be top, and greater the number, more down it will be scrolling. If number is too big, it will be outside of display. If you dont understand it, start with 100, and then make the number bigger or lower to try out where it ends.

SetFont command chooses both the font to be used for your text, as well as its size.


After these four lines, there happens several lines that are happening automatically based upon what you did before. Only thing to take care of in here, is in "CreateTextObject" that "Color" part. You can use one of the usual clors like #WHITE, #BLUE... or you can use more accurate "RGB(255, 255, 255)" which will separately decide how much Red, Green, Blue the color will have (0-255, where 255 is max) or you could even go to ARGB(255, $FFFFFF), in which case first number sets how transparent that color is, while the $FFFFFF is same as RGB, except in this case it is in different form where you are using two number-alphabets to each R, G and B. From numbers between 0 - F. by other words, ...7, 8, 9, A, B,C...


This part you dont need to undertand, but I am explaining anyway what is happening there.

CreateTExtobject is where your actual scrolling text text is created.

After this I am letting Hollywood check out the total width of that scrolling text, a Long text could well result in even 100 000 pixels.

after this i determine the x to start from location 50 + screenwidth. This means that location is 50 pixels out of screen to the right. You could leave this (50) out, it is basically sort of a buffer. That this way the scroll text wont appear to screen instantly. If you leave that 50 out,then screen will appear to screen faster. On the other hand, make 50 bigger, and it will take longer for text to appear. It is a matter of taste.

Displaytextobject acvtually makes the text to appear to screen (although at beginning it is outside of screen). This text becomes so called layer, and at this point comes problem. How do we know this layers ID so we can control it later?

Next two lines, GetAttribute and SetLayername deal with this. We are getting its ID and giving name to that ID so we can later refer to it by name.

Now comes the final part before going to action. "StartTimer(1)" this one starts a timer which is being used later to make it run at same speed on every machine.

We are now entering Repeat-until loop. One which says it will continue going through those lines betweem repeat and until, until variable "continuescrollloop" becomes TRUE. This is why it is first set to FALSE, so it keeps going between these lines.

These loop consists of two parts. First of all, another loop, which takes care of the timer a bit. This second loop is not necessary for slower machines, but if there is fast machine enough, then without this loop. there is potential problem. For it is possible that the repeat-until will be gone through so fast, that not even 1 time unit goes from timer. In this case, it will record timepassed as being 0. If we then move scrolltext based upon. Speed * 0 it results in 0, meaning it wouldnt move.

In this second loop it is being checked that at least 5 time units have went on, beforfe moving forward to the second part.

Second part is quite simple. First it is basically doing x=x-1. Although bit more complicated way, since in this case it doesnt simply minus 1, but it checks how much time have passed, and what is the speed, and based upon those two factors it decides how much x should be decreased.

Then it checks if x is already more to minus than is the width of the text, since if that is the case, then it means text have already fully scrolled from right to left and it is time to move this text back to right side, so it will start it from beginning.

Then finally we display the "scrolltext" layer to its new location, which is x, y, and as we just made the x bit different that before, it looks like text is scrolling.


as last, when it get out of the loop, it will remove that scrolltext, so it doesnt keep displaying elsewhere.



SECOND ACTION needs to be something that keeps the page staying. It can be your regualr page waiting for interaction, but in this example case lets use "WaitForRightMouse". Now it wont move past this until Right Mouse Button is pressed.

THIRD ACTION is put under SECOND ACTION, and will be "Run Code" again. This time with only one line:

Code: Select all

continuescrollloop=True
The purpose of this is to end the loop in FIRST ACTION so it can get to that last line there and stop scrolling the text.




Notice. FIRST ACTION needs to come before SECOND and THIRD.
SECOND ACTION (or whatever that keep the page still) needs to be before THIRD.

FIRST ACTION needs to be Asynchronous Action (just tick the box). This means that it keeps running along with the rest at same time, instead of being executed first before going to next script.



One more thing, hopefully you dont need to understand this, but you might in case this doesnt work.

This Line:

Code: Select all

Local layerid = GetAttribute(#BGPIC, 1, #ATTRLAYERS)
is actually very important line and it might fail. Thing is, this will check how many layers Background picture 1 has attached to it, and based upon this we know the ID number of textobject and are able to set name for it. However, there is no guarantee that Designer will be using Background ID 1 at that location, and in that case it gives wrong number. So you can keep trying changing number 1 into some other number until it works if it doesnt work with 1.

However, there is alternative way.

You can remove all following lines of code:

Code: Select all

SetFont(#SANS, 50)

CreateTextObject(1, "my text to scroll", {color=#BLUE})

DisplayTextObject(1, x, y)
Local layerid = GetAttribute(#BGPIC, 1, #ATTRLAYERS)
SetLayerName(layerid, "scrolltext")
And instead, you will create one TextObject yourself with Designer. Then you doubleclick the textobject and name it "scrolltext" and remaining code should work fine, and you dont need to worry about that BGPIC thing at all.
I would actually even recommend douing it this way, since this way you can see in designer already the text and change it etc. Will be easier for you in the end. Just harder to explain.

Oh, and do notice. This TEXTOBJECT needs to be created before FIRST ACTION, since that textobject needs to exist already by that time, so its width can be calculated.

hope this helps.

ocean77
Posts: 28
Joined: Mon Jan 28, 2019 8:34 pm

Re: Questions Regarding Hollywood

Post by ocean77 » Mon Jul 01, 2019 8:48 pm

First of all, thank you for this very in depth explanation. It helps a lot. :D
The text does indeed scroll across the screen on top of the background. It loops as well, which is brilliant. But the rest of the page is unresponsive.
I have checked the action to run asynchronously.

The page is supposed to function as a sort of menu.
Items should be highlighted at mouseover, and react to clicks.

The text is just additional information scrolling along the bottom of the page.

Bugala
Posts: 823
Joined: Sun Feb 14, 2010 7:11 pm

Re: Questions Regarding Hollywood

Post by Bugala » Mon Jul 01, 2019 9:43 pm

Here is another approach you could try:

Code: Select all

screenwidth = 640

scrollspeed = 100
y = 200

WidthOfText = GetAttribute(#TEXTOBJECT, 1, #ATTRWIDTH)
x = 50 + screenwidth


Function myscroller()

	x=x - (100 * (GetTimer(1)/1000))
	ResetTimer(1)
	If x < -50 - widthoftext Then x = 50 + screenwidth
	ShowLayer("scrolltext", x, y)

EndFunction

SetInterval(1, myscroller, 10)
StartTimer(1)

Mostly this is same as before, but this operates slightly different. I made this code based upon that you make the textobject yourself with designer and name it "scrolltext".

At beginning this is doing same things as before.

However, then there comes the FUNCTION.

You could think that each command is basically its own function. So in some sense you could think that we are adding a new command that we made ourselves, a comman that takes care of scrolling.

When you make buttons and other similar interactive stuff, Designer in practice probably has these three lines:

Code: Select all

Repeat
waitevent()
forever
This means, that Hollywood keeps repeating stuff between Repeat and Forever, well, forever, or until programs stops running.

This WaitEvent() command means that Hollywood keeps an eye if some event happens. These events are for example when mouse goes over a button. So basically Hollywood does nothing else but listens if one the pre determined events, like mouse going over a button happens, and then it does what it is supposed to do, like highlight that button.

While Hollywood is waiting for this event, it is possible to add stuff to happen at same time, even they are not actual events. This is the "SetInterval"-command I am using.

By using that "SetInterval command, I am telling hollywood to keep running that "myscroller" function, after every 10 units if possible. This means that if your cycle is faster than 10 time units, then it will wait until 10 time units have passed before executing that function. If your cycle takes 200 time units, then it will just execute "myscroller" function as fast as it can.

Because this SetInterval already sets that it will take at least 10 time units before it is executed, this is also the reason why there is no repeat-until inside to control the time.

I am also not using the timepassed variable, since I need that time only once, so I can just get it directly instead of taking it first to variable. Principle however is exactly same there.

I also dont need even the other repeat-until this time, since this time i have no need for program to keep going between those lines, since I am instead making them a function that keeps repeatedly executed every 10 time units because of the setinterval, which in this case does same as the repeat-until did before.


As a last thing. Instead of having that action that does "continuescrollloop=true", you will now need to use "StopInterval(1)" to stop it from being executed anymore.


I dont know exactly how Designer works, but there is a risk that Designer might occupy that SetInterval-ID 1 somewhere else. If this is the case, then just use some other number until you find free one. I however suppose Designer takes care not to use same numbers defined by user, so i suppose you will be able to use ID 1.

Dont know if this will fix your problem, but at least approach is different, so it might work.

ocean77
Posts: 28
Joined: Mon Jan 28, 2019 8:34 pm

Re: Questions Regarding Hollywood

Post by ocean77 » Mon Jul 01, 2019 10:05 pm

Thank you for helping out. I really appreciate it.

I copied the code to an action event. And it reports that it couldn't find text object 1 in the GetAttribute function.
Is that the text objects identifier? Should I rename it?

Sorry, I'm completely lost when it comes to coding. :oops:


EDIT: I see that in the Welcome New example there's a clapper board that keeps looping its animation while the menu on the left is fully active. I can't see any obvious script for it, but it's probably not the same thing(?)

Bugala
Posts: 823
Joined: Sun Feb 14, 2010 7:11 pm

Re: Questions Regarding Hollywood

Post by Bugala » Mon Jul 01, 2019 11:17 pm

That is actually my mistake there. Also, now I am not sure how this works in Designer, but try to replace:

Code: Select all

WidthOfText = GetAttribute(#TEXTOBJECT, 1, #ATTRWIDTH)
with

Code: Select all

WidthOfText = GetAttribute(#TEXTOBJECT, "scrolltext", #ATTRWIDTH)
Or then you could try:

Code: Select all

WidthOfText = GetAttribute(#LAYER, "scrolltext", #ATTRWIDTH)

Thing is, Textobject is basically non existing object, that it doesnt become existing until you make it into a layer.

Think it similar to enemies. Each enemy ship might have same image. Therefore there are brush ID 1 that has space ship image in it.

When you display enemy, you put new layer and attach brush ID 1 to it. So there can be 5 different enemies, each with Brush ID 1 attached to them, yet all are named different.

So when using getattribute, it is in first one referring to that textobject/enemy ship brush, while later in code "scrolltext" is actually refering to one of the 5 enemy ships that have been created already from that textobject/enemy ship brush ID 1.

But one of those two might work. Just not sure.

ocean77
Posts: 28
Joined: Mon Jan 28, 2019 8:34 pm

Re: Questions Regarding Hollywood

Post by ocean77 » Mon Jul 01, 2019 11:41 pm

If there's a string value it says it expects a number. If I put 1 it says it cannot find that particular Text object/ Layer. :?

Bugala
Posts: 823
Joined: Sun Feb 14, 2010 7:11 pm

Re: Questions Regarding Hollywood

Post by Bugala » Tue Jul 02, 2019 12:02 am

I guess have to use this system then to create the text:

Code: Select all

       screenwidth = 640

	scrollspeed = 100
	y = 200

	SetFont(#SANS, 50)

	CreateTextObject(1, "my text to scroll", {color=#BLUE})

	WidthOfText = GetAttribute(#TEXTOBJECT, 1, #ATTRWIDTH)
	x = 50 + screenwidth

	DisplayTextObject(1, x, y)
	Local layerid = GetAttribute(#BGPIC, 1, #ATTRLAYERS)
	SetLayerName(layerid, "scrolltext")


Function myscroller()

	x=x - (100 * (GetTimer(1)/1000))
	ResetTimer(1)
	If x < -50 - widthoftext Then x = 50 + screenwidth
	ShowLayer("scrolltext", x, y)

EndFunction

SetInterval(1, myscroller, 10)
StartTimer(1)


ocean77
Posts: 28
Joined: Mon Jan 28, 2019 8:34 pm

Re: Questions Regarding Hollywood

Post by ocean77 » Tue Jul 02, 2019 4:01 pm

Bugala wrote:
Tue Jul 02, 2019 12:02 am
I guess have to use this system then to create the text:

Code: Select all

       screenwidth = 640

	scrollspeed = 100
	y = 200

	SetFont(#SANS, 50)

	CreateTextObject(1, "my text to scroll", {color=#BLUE})

	WidthOfText = GetAttribute(#TEXTOBJECT, 1, #ATTRWIDTH)
	x = 50 + screenwidth

	DisplayTextObject(1, x, y)
	Local layerid = GetAttribute(#BGPIC, 1, #ATTRLAYERS)
	SetLayerName(layerid, "scrolltext")


Function myscroller()

	x=x - (100 * (GetTimer(1)/1000))
	ResetTimer(1)
	If x < -50 - widthoftext Then x = 50 + screenwidth
	ShowLayer("scrolltext", x, y)

EndFunction

SetInterval(1, myscroller, 10)
StartTimer(1)

That code seems to work as I want. Thank you so much!!!
Just one last issue to solve: As soon as I change page I suspect the code continues to run, but can no longer find the text layer it created on the previous page, so there is an error.

I tried to add a Stop Action on the subsequent page, but it could not find the code on the previous page.
I really wish I had a mind like yours so I could solve these things myself, alas.

ocean77
Posts: 28
Joined: Mon Jan 28, 2019 8:34 pm

Re: Questions Regarding Hollywood

Post by ocean77 » Tue Jul 02, 2019 6:41 pm

I tried adding Stop Action to the menu items at Mouseclick, before the next page loads, thinking that would solve it. But with the same result. It cannot find the scrolling text layer.

Bugala
Posts: 823
Joined: Sun Feb 14, 2010 7:11 pm

Re: Questions Regarding Hollywood

Post by Bugala » Wed Jul 03, 2019 1:06 am

Sorry, was writing that so late at night (Actually it is late now too) that I simply forgot to mention one thing.

In that first one there was that "Continuescrollloop=true" thing that was able to stop it.

With SetInterval(1), you need to use ClearInterval(1) to stop it. So when you change a page for example, you can use that ClearInterval command.

Idea is that when you use SetInterval, it will keep running that function every time it is at WaitEvent() moment, which is when page is waiting for some interaction. So even if you change a page, and next page gets WaitEvent(), it will then again keep running that SetInterval, as it was never removed.

By using ClearInterval, it will remove that one from stuff to go through at WaitEvents, effectively stopping the scrolling.

You could even make a button which does Run Code of "StopInterval(1)" just to see how it stops. And then you could make another button that does that SetInterval(1) part again, making you able to stop and continue it by pushing those buttons.

Post Reply