Computer Science Canada

Rewritting a buffer for my game

Author:  tjmoore1993 [ Sat May 30, 2009 4:23 pm ]
Post subject:  Rewritting a buffer for my game

What is the problem you are having?
I want it so that spaces are considered illegal characters. I have got most of the buffer completed to what I need.
Example:
When a space is entered it rejects it or something Smile

Describe what you have tried to solve this problem
I have tried too many things...


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:
function CharName (maxLength : int) : string
    var str : string := ""
    var ch : string (1)
    loop
        View.Set ("noecho")
        Input.Flush
        loop
            getch (ch)
            exit when ord (ch) = 10
            if ord (ch) = 8 then
                if str = "" then
                else
                    put "\b" ..
                    str := str (1 .. * -1)
                end if
            else
                if (ch < " ") or ("~" < ch) then
                else
                    if length (str) >= maxLength then
                    else
                        put ch ..
                        str := str + ch
                    end if
                end if
            end if
            View.Update
        end loop
        if whatrow = maxrow then
            locate (maxrow, maxcol)
            put ""
        else
            locate (whatrow + 1, 1)
        end if
        setscreen ("echo")
        result str
    end loop
end CharName

Author:  tjmoore1993 [ Sat May 30, 2009 5:03 pm ]
Post subject:  RE:Rewritting a buffer for my game

Problem solved, sorry for the inconvenience.

Turing:
function CharName (maxLength : int) : string
    var str : string := ""
    var ch : string (1)
    loop
        View.Set ("noecho")
        Input.Flush
        loop
            getch (ch)
            exit when ord (ch) = 10
            if ord (ch) = 8 then
                if str = "" then
                else
                    put "\b" ..
                    str := str (1 .. * -1)
                end if
            else
                if (ch < "!") or ("~" < ch) then % FIXED
                else
                    if length (str) >= maxLength then
                    else
                        put ch ..
                        str := str + ch
                    end if
                end if
            end if
            View.Update
        end loop
        if whatrow = maxrow then
            locate (maxrow, maxcol)
            put ""
        else
            locate (whatrow + 1, 1)
        end if
        setscreen ("echo")
        result str
    end loop
end CharName

Author:  corriep [ Sat May 30, 2009 8:40 pm ]
Post subject:  Re: Rewritting a buffer for my game

Quick tip, instead of this:
Turing:
if str = "" then
else
    put "\b" ..
    str := str (1 .. * -1)
end if
Use this
Turing:
if str not= "" then % you can even use ~=
    put "\b" ..
    str := str (1 .. * -1)
end if

Author:  tjmoore1993 [ Sat May 30, 2009 9:21 pm ]
Post subject:  RE:Rewritting a buffer for my game

I heard adding more to the decision itself can cause a tiny offset. I am going for efficiency and so far I've done a good job.

Before:
Video Memory : 29MB maximum
Memory : 43MB maximum

After
Video Memory : 10MB maximum
Memory : 5MB maximum

Soon to be released.


: