Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Scrolling title
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Lapsus Antepedis




PostPosted: Tue Jul 05, 2005 3:47 am   Post subject: Scrolling title

Yet another early-morning program from Lapsus!
This process (sorry Delos!) scrolls a string across
the title bar of the program run window thanks to
some string manipulation! It actually looks pretty
cool, and it also scrolls while in the startbar. I
just need how to turn it off to change the title string
if needed.

Thoughts? Comments?

Turing:

process titlescroll (title : string, display, del : int)

    % 'title' is the string that will be scrolled in the titlebar
    % 'display' is the number of characters that will be shown at once
    % 'del' Is the delay between updates to the titlebar

    const header : string := "title:"
    var thing : string := ""
    for i : 1 .. display
        thing += ' '
    end for
    thing += title
    for i : 1 .. display
        thing += ' '
    end for
    var titlestring : string
    titlestring := header
    loop
        for i : 1 .. length (thing) - display
            titlestring := header
            for ii : 0 .. display - 1
                titlestring += thing (i + ii)
            end for
            View.Set (titlestring)
            delay (del)
        end for
    end loop
end titlescroll

fork titlescroll ("Yes it was necessary to make this into a process seeing as the rest of the program would not run otherwise!", 20, 100)

put "This title scrolling program was written by Lapsus Antepedis in 2005"
put "Feel free to use this code in your programs as long as you give credit"
put "I always seem to do my best programming around 3 in the morning..."
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue Jul 05, 2005 8:31 am   Post subject: (No subject)

Intriguing. I've tried to run your code four times, but every time I get the "The environment (not your program) has crashed!" error. Yet, it seems to be your program that's causing the trouble, since my other programs work. Thinking

*A minute later*
I was wondering why you didn't have any drawing commands. Then I realized you were adjusting the title bar. I added the "title:" + before the titlestring and it now works fine.
code:
View.Set ("title:" + titlestring)


*A while later*
Now I'm really confused, because titlestring starts with "title:". And yet, when I changed the View.Set it worked as it should. When I left it alone, I discovered that just before the View.Set line titlestring has a value of "title:". Nothing more. Opening a new Turing window and running the following causes the Turing to crash in the same manner.
code:

View.Set ("title:")

I don't know why titlestring's value is merely "title:" however. It's not as though that second for loop
code:

            for ii : 0 .. display - 1
                titlestring += thing (i + ii)
            end for

will not execute. display - 1 is 19, which is definately bigger than 0. So that should run.

*A small amount of time later*
Oh. It adds to the titlestring variable, but it adds spaces.
code:

View.Set ("title:                                 ")

That still causes the program to crash. It seems you need to have at least some title at any given time. You'll need to modify the code such that there's always at least one character in the title at any time.

Here's my modification. I've changed it into procedure format, though it now relies on the existance of a global variable called starting_character. Sad On the plus side, it's been shortened to eleven lines.
Turing:

var starting_character := 0
procedure titlescroll (title : string, display : int)
    var full_title := repeat (" ", display) + title
    if starting_character < length (full_title) then
        starting_character += 1
    else
        starting_character := 1
    end if
    if starting_character <= length (full_title) - display then
        View.Set ("title:[" + full_title (starting_character .. starting_character + display) + "]")
    else
        View.Set ("title:[" + full_title (starting_character .. *) + full_title (1 .. display - (length (full_title) - starting_character)) + "]")
    end if
end titlescroll

loop
    titlescroll ("Scrolling Title.  Lots of text.", 20)       %cannot have commans (,) or semi-colons (;) in the title

    put "Main program is running"
    delay (75)
end loop

The "[" has to be there (or , something has to be there. Could be a colon or a period...) or else it will not give the desired effect. Try taking it out and see what I mean. The reason is that this
code:
View.Set ("title:                                a")

is the same as
code:
View.Set ("title:a")


I don't like how that "]" is jumping around. Too bad the title is not a fixed width font. Anyone know what font that is? We could do some Font.Width()ing to make it look better.

I like this idea Lapsus Antepedis. I think this would go nicely into Turing's Window module. Very Happy

*EDIT*
Actually, the other thing about my code is that it does not rely on it's own time keeping. This procedure would not work so well in a turn-based game... For that, you'd either have to go to procedure format or have your main loop look like this:
code:

loop
    loop                                %input loop
        titlescroll (parameters)
        delay (title_scroll_delay)
        %get input by some means other than the ones that pause the program
        %such as get, getch, and Mouse.ButtonWait.
        exit when input_has_been_made
    %main code
end loop
Lapsus Antepedis




PostPosted: Tue Jul 05, 2005 2:00 pm   Post subject: (No subject)

Wow, I really have to stop programming with 3.1.1a...
I'll have to get my code at home and try to make it not eat the environment. It seems odd that the View.Set works differently between the different versions of turing... I'll see if I can get it to work whenever I get back home, and then find my darn install disk...
MysticVegeta




PostPosted: Wed Jul 06, 2005 3:08 pm   Post subject: (No subject)

That could be an idea for Stargate's post ->
old method
code:
View.Set("title:XXXXXX")

new method
code:
View.Set("scrollTitle:XXXXXXX")
Cervantes




PostPosted: Wed Jul 06, 2005 6:13 pm   Post subject: (No subject)

Yeah, that would be nice, but that is not possible. View.Set is an external procedure, and hence cannot be modified. That is to say, it's built right into the Turing .exe, as far as I know. The closest we could get is adding a new procedure to the View and Window modules, which is okay, I guess.
[Gandalf]




PostPosted: Wed Jul 06, 2005 7:22 pm   Post subject: (No subject)

Yeah, which is what we are doing. It's too bad (well, not really) that they didn't make more of their commands directly in Turing so that we could edit them Smile.

Quote:
The "[" has to be there (or , something has to be there. Could be a colon or a period...) or else it will not give the desired effect. Try taking it out and see what I mean.

Why not just have a blank space? I think it would work, wouldn't it?
Cervantes




PostPosted: Wed Jul 06, 2005 7:31 pm   Post subject: (No subject)

I explained why that doesn't work just after that quotation.
I suppose I should have said "some non-space, non-comma, non-semi-colon" character has to be there.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: