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

#1 2013-01-24 06:00:09

GhostInTheMachine
Scratcher
Registered: 2013-01-16
Posts: 10

Variable Newlines

Are they possible? I'm trying to make a terminal OS in Scratch, and I need this for the output buffer.

Offline

 

#2 2013-01-24 11:15:07

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: Variable Newlines

Scratch doesn't natively support escaping newline characters (\n), though if you output to a list, you could take a string and add newlines to the output yourself, roughly like this:

when gf clicked
delete [all] of [Terminal v] //list that the user will see
set [String v] to [dunno if this works,\nyou go figure.] //our string, with a escaped newline that we'll check for
set [i v] to [1] //iterator
set [output v] to [] //string that will be added to the list
repeat until <(i) > (length of (String))>
    if <(letter (i) of (String)) = [\]> //check for escape character
        if <(letter ((i) + [1]) of (String)) = [n]> //is it a newline?
            add (output) to [Terminal v] //add our string so far to the Terminal. It could be empty.
            set [output v] to [] //reset output string
            change [i v] by [2] //skip the newline character; next letter
        end
    else
        set [output v] to (join (output) (letter (i) of (String))) //add current letter to output string
        change [i v] by [1] //next letter
    end
end
if <not <(output) = []>> //if output string is not empty (i.e. newline at the very end)
    add (output) to [Terminal v]
end


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

Board footer