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

Username:   Password: 
 RegisterRegister   
 TextFields Help
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
StarGateSG-1




PostPosted: Mon Jul 11, 2005 11:45 pm   Post subject: TextFields Help

Digging my way back into turing isn't easy, so I come to you guys again, with a another problem. I know that it can be fixed I just can't wrap my mind around it. Here it is, the textfiled crashes when you go to enter a letter??

New file, redownload please!



Test.zip
 Description:
Here is the file, run the program and click on load or save button, then try and enter text!

Download
 Filename:  Test.zip
 Filesize:  1.14 KB
 Downloaded:  145 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue Jul 12, 2005 7:01 am   Post subject: (No subject)

I'm not sure if this will fix your problem or not, but you may want to think about keeping everything at the base level. That is, you declare all your GUI buttons and textfields etc. at the program level, then when you click on something you run a procedure that merely shows some widgets and hides others.
BTW, you misspelled "wrap". Laughing
StarGateSG-1




PostPosted: Tue Jul 12, 2005 9:57 am   Post subject: (No subject)

Thank you but I don't think that will work, I will try but I have a feeling that isn't the problem, I will take a closer look though at looking at that, I will fix the spelling mistake tho.
Delos




PostPosted: Tue Jul 12, 2005 10:05 am   Post subject: (No subject)

Oh man...
StarGate! Carrying implicit calls to GUI.ProcessEvent within button action-procedures is not a good idea. Despite not having the various GUI.ResetQuit()'s you might need to smooth things out...it just complicates matters.
Turing GUI is unstable enough as it is, so you should really only have one main loop that handles it all. Within this loop, you can have normal, everyday commands going on as well.

One option you might want to look into is instead of opening an entirely new window, you could have all your widgets in one window. When you click on, say, Load - all widgets that aren't needed are disabled, and those that are needed are made visible, and enabled. Once they've done their jobs, reverse.

Or, you could be brave an make your own custom GUI!
StarGateSG-1




PostPosted: Tue Jul 12, 2005 10:25 am   Post subject: (No subject)

I can't do that, but yes it would be nicer but if you look at my code, you see that thee is a loading and Saving wondow, so do use your method, I would have to diable all wigets not in use then, change the screen size, I wnat the effect of the other window underneath, I don't think the problem is related to the order they are in.


Here is the problem code form the GUI files.

code:
% Check widgets
        var widget : ^GenericWidgetBodyClass := WidgetGlobals.firstWidget
        loop
            exit when widget = nil
            if widget -> GetWindow = window and
                    objectclass (widget) >= GenericActiveWidgetClass and
                    GenericActiveWidgetClass (widget).ConsiderKeystroke (ch)
                    then
                % Was a widget shortcut.
                return
            end if
            widget := widget -> GetNext
        end loop


Here is the help file code which runs fine, and is were I got the snytax.

code:

  import GUI
        View.Set ("graphics:200;100")
       
        var nameTextField, addressTextField : int   % The Text Field IDs.
       
        procedure NameEntered (text : string)
            GUI.SetSelection (addressTextField, 0, 0)
            GUI.SetActive (addressTextField)
        end NameEntered
       
        procedure AddressEntered (text : string)
            GUI.SetSelection (nameTextField, 0, 0)
            GUI.SetActive (nameTextField)
        end AddressEntered
       
        GUI.SetBackgroundColor (gray)
        var quitButton := GUI.CreateButton (52, 5, 100, "Quit", GUI.Quit)
        nameTextField := GUI.CreateTextFieldFull (50, 70, 100, "",
            NameEntered, GUI.INDENT, 0, 0)
        addressTextField := GUI.CreateTextFieldFull (50, 40, 100, "",
            AddressEntered, GUI.INDENT, 0, 0)
        var nameLabel := GUI.CreateLabelFull (45, 70, "Name", 0, 0,
            GUI.RIGHT, 0)
        var addressLabel := GUI.CreateLabelFull (45, 40, "Address", 0, 0,
            GUI.RIGHT, 0)
        loop
            exit when GUI.ProcessEvent
        end loop
       
        GUI.Dispose (quitButton)
        colorback (gray)
        Text.Locate (maxrow - 1, 1)
        put "Name = ", GUI.GetText (nameTextField)
        put "Address = ", GUI.GetText (addressTextField) ..


Here is my program, as you can see everything is the same.

code:
import GUI
View.Set ("graphics:max;max,nobuttonbar,nocursor,noecho,xor,title:Dark Tides: The Beginnings")
GUI.SetBackgroundColour (gray)

var Map_Canvas, Map_Frame, Message_Frame, Option_Frame, All_Frame, Message_Box : int
var Load_Frame, Load_Box, LoadName, Save_Frame, Save_Box, SaveName, Help_Frame, Help_Box : int
var Load, Save, New, Quit, Help, Ok, Back : int
var Save_Window, Load_Window, Help_Window, NewGame_Window : int
var streamNumber : int
var fileName : string

procedure Active
    View.Set ("invisible")
    Window.SetActive (defWinId)
end Active

procedure FileLoadName (text : string)
    GUI.SetSelection (LoadName, 0, 0)
    GUI.SetActive (LoadName)
end FileLoadName

procedure FileSaveName (text : string)
    GUI.SetSelection (SaveName, 0, 0)
    GUI.SetActive (SaveName)
end FileSaveName

procedure New_Game

end New_Game

procedure Load_Game
    Load_Window := Window.Open ("position:center;center,graphics:600;400")
    GUI.SetBackgroundColour (gray)
    Load_Frame := GUI.CreateFrame (10, 5, maxx - 10, maxy - 3, GUI.EXDENT)
    Load_Box := GUI.CreateTextBox (30, 70, maxx - 60, maxy - 80)
    LoadName := GUI.CreateTextFieldFull (50, 40, 200, "*.sav", FileLoadName, GUI.INDENT, 0, 0)
    Ok := GUI.CreateButton (300, 35, 0, "Open", New_Game)
    Back := GUI.CreateButton (400, 35, 0, "Close", Active)
    streamNumber := Dir.Open (Dir.Current + "/Data/Saved Games")
    assert streamNumber > 0
    loop
        fileName := Dir.Get (streamNumber)
        exit when fileName = ""
        GUI.AddLine (Load_Box, fileName)
    end loop
    Dir.Close (streamNumber)
    loop
        exit when GUI.ProcessEvent
    end loop
end Load_Game

procedure Save_Game
    Save_Window := Window.Open ("position:center;center,graphics:600;400")
    GUI.SetBackgroundColour (gray)
    Save_Frame := GUI.CreateFrame (10, 5, maxx - 10, maxy - 3, GUI.EXDENT)
    Save_Box := GUI.CreateTextBox (30, 70, maxx - 60, maxy - 80)
    SaveName := GUI.CreateTextFieldFull (50, 40, 200, "*.sav", FileSaveName, GUI.INDENT, 0, 0)
    Ok := GUI.CreateButton (300, 35, 0, "Open", New_Game)
    Back := GUI.CreateButton (400, 35, 0, "Close", Active)
    streamNumber := Dir.Open (Dir.Current + "/Data/Saved Games")
    assert streamNumber > 0
    loop
        fileName := Dir.Get (streamNumber)
        exit when fileName = ""
        GUI.AddLine (Save_Box, fileName)
    end loop
    Dir.Close (streamNumber)
    loop
        exit when GUI.ProcessEvent
    end loop
end Save_Game

procedure New_Start

end New_Start

procedure Main
    GUI.Quit
    View.Set ("Invisible")
    %MainScreen
end Main

procedure Help_Game
    Help_Window := Window.Open ("position:center;center,graphics:300;200")
    GUI.SetBackgroundColour (gray)
    Save_Frame := GUI.CreateFrame (3, 3, maxx - 5, maxy - 5, GUI.EXDENT)
    Help_Box := GUI.CreateTextBox (10, 10, maxx - 20, maxy - 20)
end Help_Game

Load := GUI.CreateButton (15, maxy - 25, 0, "New Game", New_Start)
Save := GUI.CreateButton (100, maxy - 25, 0, "Load Game", Load_Game)
New := GUI.CreateButton (185, maxy - 25, 0, "Save Game", Save_Game)
Quit := GUI.CreateButton (270, maxy - 25, 0, "Quit Game", Main)
Help := GUI.CreateButton (355, maxy - 25, 0, "Game Help", Help_Game)

All_Frame := GUI.CreateFrame (0, 0, maxx, maxy, GUI.EXDENT)
Option_Frame := GUI.CreateFrame (maxx - 200, 10, maxx - 10, maxy - 10, GUI.EXDENT)
Map_Frame := GUI.CreateFrame (10, 155, maxx - 220, maxy - 30, GUI.EXDENT)
Map_Canvas := GUI.CreateCanvas (20, 165, maxx - 250, maxy - 200)
Message_Frame := GUI.CreateFrame (10, 5, maxx - 220, 150, GUI.EXDENT)
Message_Box := GUI.CreateTextBox (20, 10, maxx - 250, 135)

loop
    exit when GUI.ProcessEvent
end loop


I tryed moving each piece of code out of a procedure and move them to their own files, but I still got the same error, I want to use this later to Add in Save File, And Open File for the GUI, with modications.
jamonathin




PostPosted: Tue Jul 12, 2005 10:30 am   Post subject: (No subject)

Delos wrote:

Or, you could be brave an make your own custom GUI!

Go with that. In my opinion, GUI is slow is for lazy people. You can easily make 90% of the GUI commands without all that much effort, all you have to do is think of what GUI did when it did whatever command, such as a button.

For a button, just:
code:

var a,b,c,d:int := 100
c:=150
d:=120
var mx,my,mz:int
proc mybutton
drawfilloval(Rand.Int(1,maxx),Rand.Int(1,maxy),20,20,2)
end mybutton
View.Set("offscreenonly")
loop
mousewhere(mx,my,mz)
drawfillbox(a,b,c,d,grey)
if mx > a and my >b and mx <c and my <d then
drawfillbox(a,b,c,d,22)
if mz = 1 then
drawfillbox(a,b,c,d,24)
mybutton
end if
end if
drawbox(a,b,c,d,black)
View.Update
delay(10)
end loop

Or something to that effect, and you could just shove everything in a array so it's more organized. Text fields are tricky, but ive done them before, so they cant be too hard.
StarGateSG-1




PostPosted: Tue Jul 12, 2005 1:35 pm   Post subject: (No subject)

I really, donl't think that is the problem though, I have played around with that, There is a deeper problem here, that that doensa't fix I have tryed all of those method's. This is a brainstorming question, have you guys looked at the GUI,Widgets, also this is not liek rewriting a button command, I would have to rewrite most fo the GUI, all like 50 of them, that is to much work, I know there is a way to fix this is just hasn't been found yet.
Cervantes




PostPosted: Wed Jul 13, 2005 6:52 am   Post subject: (No subject)

Two things, Jamonathin.
First, why do you use the variables, a, b, c, and d for the coordinates x1, y1, x2, and y2? Why not use x1, y1, x2, and y2? Confused

Second, it looks like you've got what the Turing help calls an action procedure. If you were to make this into a class, you could incorporate the call of that action procedure within your clicked method. Or you could do what I did and make the clicked method a function; if it returns true, you go into your code for that button. This could involve some unique code, some procedure/function calling (with varying parameters, which Turing's GUI will not let you do. A button's action procedure cannot have parameters and cannot be a function. A textfields action procedure must have one parameter, and it is a string).

Stargate: I really think you should do as Delos and I have suggested and make everything work within the same loop. If this becomes a larger project, it will save you a lot of trouble.
Sponsor
Sponsor
Sponsor
sponsor
StarGateSG-1




PostPosted: Wed Jul 13, 2005 10:15 am   Post subject: (No subject)

Unfortunatly, I tryed that, I think I methioned that somewere, and it didn;t work, even if you take parts out of a program sae you take just the loading out, give it all the variables and such, it won't run, that is why I am still working on it.

Edit: Feel free to try your method Cervantes, I have failed but maybe you can succeed!
jamonathin




PostPosted: Wed Jul 13, 2005 11:39 am   Post subject: (No subject)

Three things, Cervantes. Razz

First, I used variables a, b, c, and d for the coordinates x1, y1, x2, and y2 because it's faster than writing x1, y1, x2, and y2. And it's just a personal 'favorite', if you will, to use them, so when I draw a box, or call Pic.New, I can simple use (a,b,c,d).

Second, I'm just starting to learn what classes are. In other words, I have no ****ing clue what they do lol. As for as 'Advanced Turing/Programming', all I know are multi-dimensioned arrays, records, and little tricks here and there. All of which you could teach to a grade 11 newbie. I just need to find one day this summer where I'm doing absolutely nothing, and I'mm gonan whip through your walkthrough and just learn everyting, cuz really, it's Turing. Not that hard to pick up on.

Third, thanks for taking the time to spell Jamonathin correctly Smile. I've gotten some unique modifications of it throughout CompSci.
Aziz




PostPosted: Wed Jul 13, 2005 12:58 pm   Post subject: (No subject)

Check out my battleship game

i don't use any GUI or get commands. i use if hasch then getch and Font.Draw. It's called idiot-proof input. Smile check it out. its in the font module. next week (when im at my dads) ill post my idiot-proof input (string, int, negatives, decimals) assigment. commented and all Smile maybe ill make a tutorial? Would anyone find that useful?
StarGateSG-1




PostPosted: Wed Jul 13, 2005 4:05 pm   Post subject: (No subject)

Honestly, no offence I don;t like your method, by the way besides the graphics and sounds your game is low quality, you have to answer math problems?? what is with that on top of that you get no time, I read the question and hit one number it ended, Plus if you close the window the whole program closes??, Every game like that needs A.I or hotseat (player vs player on same computer.).

By the way that is not idiot prove, that will just mess you up, it is a sloppy way to do code in my book, get works find, or GUI even better, I have never heard of a such a method, and woundn't find it effective. ( I loooked over ur code.)
Aziz




PostPosted: Wed Jul 13, 2005 4:34 pm   Post subject: (No subject)

Whoa Whoa there buddy, not so much hostility, eh? Laughing You didn't see me bash your program did you? I don't want no beef *moo*

First, the math problems are there because they had to be, it had to be educational, it was my school ISU, and my teacher made it have to be educational. And I never ever said that my graphics/sound were the best, but damn, there's no reason to call them low quality. I was just trying to help. Way to be closed-minded. And I think the time limit is decent, if not the best. If a 40 year old women who types with one finger can do it, I don't think it's too tough, no offense. If I had more time to had AI, I would've, but I decided to go with solitaire-style, because of time-constraints. And if you read my post, I said that the bug where the program crashes is a bug, but I don't think there's a way to fix it :S

And if you don't think my methods of input are idiot-proof, please, be my guest, try to get around them. You can't type in a letter, decimal, or any thing except -, and 0-9, and only a negative at the beginning of a line. And you can't backspace past the back of a line. Using a get command, you're player could time in "nine" and boom, program crashes. It's alright if you don't agree, but please, back it up and be a little mature.
StarGateSG-1




PostPosted: Wed Jul 13, 2005 8:09 pm   Post subject: (No subject)

First off I wasn't bashing your program, you need to understand that, and if you took it that way I am sorry, but it is called construtive criticism, nothing more, just idea's about things you could improve, GUI is the way of the future and the past, there is nothing better, most of the time, my main though and worry is that you don't know how to use GUI and so you find crude method's around it, that is not a good idea. The sounds and graphics are great the code is not. For educational purposes math problems are not a good idea, try using facts that can be read and such, or take them out for posting on compsci, because no one will care here, games are suppose to be relaxing and not have to be paying attention constantly. That is why a time limit is a bad idea. You don;t even really need A.I, but a hotseat mode is very important, otherwise the game gets boring very fast. THe methods are idiot prove are solid to a point, unlike GUI which can't be broken, because it is worked right into it. Try slaming of hit your fist against the keyboard that will crash it sometimes.

Most advice is good, but if you look at my prgram it doesn't work, it is important to undersatnd the problem before you give advice, the method I use contains a palce to enter text and then grab it but other stuff is in the window to, Your method works really well if I opened a new window for every Input but that is impratical, as you can see.
Cervantes




PostPosted: Wed Jul 13, 2005 9:24 pm   Post subject: (No subject)

Calm down, guys.

I don't want to re-download your game, Aziz, but I'm curious: have you accounted for integer overflows, or strings that are longer than 255 characters? (Apart from assuming that the user can't type that much in within the time limit. Wink)

StargateSG-1 wrote:

GUI is the way of the future and the past, there is nothing better, most of the time, my main though and worry is that you don't know how to use GUI and so you find crude method's around it, that is not a good idea.

GUI is fine and all, but it's a good idea to know how to do things yourself. There's nothing crude about it, especially given how disgusting Turing's standard GUI looks! Laughing

StarGateSG-1 wrote:

get works find, or GUI even better, I have never heard of a such a method, and woundn't find it effective.

Aziz wrote:

Using a get command, you're player could time in "nine" and boom, program crashes.

Right-o. get is crap. That's just begging for your user to crash your program. Using the
code:

if hasch then
    getch (CHAR)
    %handle CHAR
end if

structure is quite good. For handling text, it's the best! Smile
And you say GUI is better, StarGate, but that's not necessarily true. See, using Turing's GUI forces your code to take on a certain, often undesirable (and ugly) structure. Sometimes (like if you've only got one button or one textfield) that's just too high a price.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: