Retrieve text from StringGadget that is inside ContainerGadget
- Distorted Pixel
- Enthusiast
- Posts: 303
- Joined: Sun Aug 29, 2021 4:34 am
Retrieve text from StringGadget that is inside ContainerGadget
Hi,
If I run the code of the one window that has the StringGadget inside the ContainerGadget it debugs the user typed text fine, but if I run the same window with the rest of my program it will not debug at all. Why would this happen?
If I run the code of the one window that has the StringGadget inside the ContainerGadget it debugs the user typed text fine, but if I run the same window with the rest of my program it will not debug at all. Why would this happen?
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? 
No one cares how much you know until they know how much you care

No one cares how much you know until they know how much you care
Re: Retrieve text from StringGadget that is inside ContainerGadget
An example code that would generate this "anomaly" would be helpful...Distorted Pixel wrote: Why would this happen?
Tripolar, no?Distorted Pixel wrote: To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar?![]()

If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Except on this sentence...
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Retrieve text from StringGadget that is inside ContainerGadget
The problem as stated cannot be solved. There are just too many reasons this would happen. Try to put together a snippet where it's happening and post that.
BERESHEIT
- Distorted Pixel
- Enthusiast
- Posts: 303
- Joined: Sun Aug 29, 2021 4:34 am
Re: Retrieve text from StringGadget that is inside ContainerGadget
:
I have been using IceDesigner for my interface creating. As I said in my first post, If I run just the one window code it works, but running it in the whole program it will not debug the user typed string.
Below isn't the code including the IceDesigner code, but it is doing the same thing even though it is running by itself with no other previous windows as in my program.
[Edit] I just rearranged the drawing code to be more like original code when it comes to the images. (In the original code I actually load an image into an ImageGadget and disable the gadget. It is as big as the main window and redrawn to the ScreenOuput for the WindowedScreen.)
Example code:
I can't say I have heard of thatboddhi Said:
Tripolar no?

I have been using IceDesigner for my interface creating. As I said in my first post, If I run just the one window code it works, but running it in the whole program it will not debug the user typed string.
Below isn't the code including the IceDesigner code, but it is doing the same thing even though it is running by itself with no other previous windows as in my program.
[Edit] I just rearranged the drawing code to be more like original code when it comes to the images. (In the original code I actually load an image into an ImageGadget and disable the gadget. It is as big as the main window and redrawn to the ScreenOuput for the WindowedScreen.)
Example code:
Code: Select all
; window 1
EnableExplicit
Global PlayerName.s, return_key_down, String_1
Global Cont_1 = 0
If OpenWindow(0, 0, 0, 600, 250,"ContainerGadget with StringGadget",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
CreateImage(0, 600, 250, 32)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Default)
Box(0, 0, 600, 250, RGB(0, 0, 110))
StopDrawing()
ImageGadget(0, 0, 0, 600, 250, ImageID(0))
DisableGadget(0, #True)
InitSprite() : InitKeyboard()
OpenWindowedScreen(WindowID(0), 0, 0, 600, 250, #True, #False, #False)
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Default)
Box(0, 0, 600, 250, RGB(0, 0, 110))
StopDrawing()
ContainerGadget(Cont_1, 115, 70, 350, 150, #PB_Container_Raised)
SetGadgetColor(Cont_1,#PB_Gadget_BackColor, RGB(0, 0, 150))
StringGadget(1, 45, 70, 250, 25, "")
SetActiveGadget(1)
CloseGadgetList()
Repeat
ExamineKeyboard()
PlayerName = GetGadgetText(String_1)
If KeyboardPushed(#PB_Key_Return) And return_key_down = #False
Debug PlayerName
return_key_down = #True
ElseIf KeyboardReleased(#PB_Key_Return) And return_key_down = #True
return_key_down = #False
SetGadgetText(String_1, "")
Break
EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Last edited by Distorted Pixel on Wed Jul 03, 2024 1:02 am, edited 2 times in total.
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? 
No one cares how much you know until they know how much you care

No one cares how much you know until they know how much you care
Re: Retrieve text from StringGadget that is inside ContainerGadget
What is your problem?
Code: Select all
EnableExplicit
Global PlayerName.s, return_key_down, String_1
Global Cont_1 = 0
If OpenWindow(0, 0, 0, 600, 250,"ContainerGadget with StringGadget",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
SetWindowColor(0, RGB(0, 0, 190))
InitSprite() : InitKeyboard()
OpenWindowedScreen(WindowID(0), 0, 0, 600, 250, #True, #False, #False)
CreateImage(0, 600, 250, 32)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Default)
Box(0, 0, 600, 250, RGB(10, 10, 110))
StopDrawing()
ImageGadget(0, 0, 0, 600, 250, ImageID(0))
DisableGadget(0, #True)
ContainerGadget(Cont_1, 115, 70, 350, 150, #PB_Container_Raised)
SetGadgetColor(Cont_1,#PB_Gadget_BackColor, RGB(0, 0, 150))
StringGadget(1, 45, 70, 250, 25, "")
SetActiveGadget(1)
CloseGadgetList()
Repeat
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Return) ;And return_key_down = #False
return_key_down = #True
ElseIf KeyboardReleased(#PB_Key_Return) ;And return_key_down = #True
return_key_down = #False
Debug GetGadgetText(1)
;Break
EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Egypt my love
- Distorted Pixel
- Enthusiast
- Posts: 303
- Joined: Sun Aug 29, 2021 4:34 am
Re: Retrieve text from StringGadget that is inside ContainerGadget
The above code in my first post is just a quick example code that does the same thing as my original code. It won't debug the user typed string to the debug window. The debug opens, but is blank
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? 
No one cares how much you know until they know how much you care

No one cares how much you know until they know how much you care
Re: Retrieve text from StringGadget that is inside ContainerGadget
It seems that Your IF conditions are wrong
No problem getting the text from the string gadget inside a container or no container at all
No problem getting the text from the string gadget inside a container or no container at all
Egypt my love
- Distorted Pixel
- Enthusiast
- Posts: 303
- Joined: Sun Aug 29, 2021 4:34 am
Re: Retrieve text from StringGadget that is inside ContainerGadget
I have fixed my example code in the first post. I found that I had a "1" in places that should have been String_1.
Unfortunately, it didn't help with figuring out why my original code is not working with the rest of the program. When I run the whole program, I get to the screen that the user can type in their name and press return key and I type a name and press return key and nothing happens. It doesn't clear what I type or close the window.
IceDesigner uses a fair amount of CompilerIf/EndCompilerIf statements and for me that is more complicated to some degree. I am also trying to use only one main game loop. So far up to this enter player name screen I have succeeded, but this screen is haunting me lol.
Unfortunately, it didn't help with figuring out why my original code is not working with the rest of the program. When I run the whole program, I get to the screen that the user can type in their name and press return key and I type a name and press return key and nothing happens. It doesn't clear what I type or close the window.
IceDesigner uses a fair amount of CompilerIf/EndCompilerIf statements and for me that is more complicated to some degree. I am also trying to use only one main game loop. So far up to this enter player name screen I have succeeded, but this screen is haunting me lol.
Code: Select all
EnableExplicit
Global PlayerName.s, return_key_down
Global Cont_1 = 0
Global String_1 = 1
If OpenWindow(0, 0, 0, 600, 250,"ContainerGadget with StringGadget",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
CreateImage(0, 600, 250, 32)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Default)
Box(0, 0, 600, 250, RGB(0, 0, 110))
StopDrawing()
ImageGadget(0, 0, 0, 600, 250, ImageID(0))
DisableGadget(0, #True)
InitSprite() : InitKeyboard()
OpenWindowedScreen(WindowID(0), 0, 0, 600, 250, #True, #False, #False)
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Default)
Box(0, 0, 600, 250, RGB(0, 0, 110))
StopDrawing()
ContainerGadget(Cont_1, 115, 70, 350, 150, #PB_Container_Raised)
SetGadgetColor(Cont_1,#PB_Gadget_BackColor, RGB(0, 0, 150))
StringGadget(String_1, 45, 70, 250, 25, "")
SetActiveGadget(String_1)
CloseGadgetList()
Repeat
ExamineKeyboard()
PlayerName = GetGadgetText(String_1)
If KeyboardPushed(#PB_Key_Return) And return_key_down = #False
Debug PlayerName
return_key_down = #True
ElseIf KeyboardReleased(#PB_Key_Return) And return_key_down = #True
return_key_down = #False
SetGadgetText(String_1, "")
Break
EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? 
No one cares how much you know until they know how much you care

No one cares how much you know until they know how much you care
Re: Retrieve text from StringGadget that is inside ContainerGadget
You have an ImageGadget 0 and a ContainerGadget Cont_1 which is also 0, so that's a conflict right there. Your StringGadget problem might have a similar reason.
Re: Retrieve text from StringGadget that is inside ContainerGadget
Works:
Code: Select all
EnableExplicit
Enumeration Gadget
#Img_1
#Cont_1
#String_1
EndEnumeration
Global PlayerName.s, return_key_down
If OpenWindow(0, 0, 0, 600, 250,"ContainerGadget with StringGadget",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
CreateImage(0, 600, 250, 32)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Default)
Box(0, 0, 600, 250, RGB(0, 0, 110))
StopDrawing()
ImageGadget(#Img_1, 0, 0, 600, 250, ImageID(0))
DisableGadget(#Img_1, #True)
InitSprite() : InitKeyboard()
OpenWindowedScreen(WindowID(0), 0, 0, 600, 250, #True, #False, #False)
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Default)
Box(0, 0, 600, 250, RGB(0, 0, 110))
StopDrawing()
ContainerGadget(#Cont_1, 115, 70, 350, 150, #PB_Container_Raised)
SetGadgetColor(#Cont_1,#PB_Gadget_BackColor, RGB(0, 0, 150))
StringGadget(#String_1, 45, 70, 250, 25, "")
SetActiveGadget(#String_1)
CloseGadgetList()
Repeat
ExamineKeyboard()
PlayerName = GetGadgetText(#String_1)
If KeyboardPushed(#PB_Key_Return) And return_key_down = #False
Debug PlayerName
return_key_down = #True
ElseIf KeyboardReleased(#PB_Key_Return) And return_key_down = #True
return_key_down = #False
SetGadgetText(#String_1, "")
Break
EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
- Distorted Pixel
- Enthusiast
- Posts: 303
- Joined: Sun Aug 29, 2021 4:34 am
Re: Retrieve text from StringGadget that is inside ContainerGadget
In my last post with code, I changed certain variable numbers so they would be different and it works.#NULL wrote: Wed Jul 03, 2024 5:41 am You have an ImageGadget 0 and a ContainerGadget Cont_1 which is also 0, so that's a conflict right there. Your StringGadget problem might have a similar reason.
@infratec
Yes, that code works, and so does the code in my last post with code.
I did forget to mention that in the original code, all gadgets are set with #PB_Any so they are all different
I will try to put together a new example created with IceDesigner. I will post it when I get it finished.
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? 
No one cares how much you know until they know how much you care

No one cares how much you know until they know how much you care
Re: Retrieve text from StringGadget that is inside ContainerGadget
IceDesign offers many ways to do things. Personally I don't like to use '#PB_Any'.
I find it adds a lot of 'fluff', although I have used it in some instances.
I prefer to use the '#Constants' option along with the 'Bind All Gadgets Events' flag, so that my events are isolated to my liking.
Just say'in
I find it adds a lot of 'fluff', although I have used it in some instances.
I prefer to use the '#Constants' option along with the 'Bind All Gadgets Events' flag, so that my events are isolated to my liking.
Just say'in

- It was too lonely at the top.
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Re: Retrieve text from StringGadget that is inside ContainerGadget
That's how I see it too.
I also always use constants with named enumeration.
No unnecessary variables, clear assignment.
With my EventDesigner, I can then also call the function for events with a virtual table.
I also always use constants with named enumeration.
No unnecessary variables, clear assignment.
With my EventDesigner, I can then also call the function for events with a virtual table.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
- Distorted Pixel
- Enthusiast
- Posts: 303
- Joined: Sun Aug 29, 2021 4:34 am
Re: Retrieve text from StringGadget that is inside ContainerGadget
[/quote]
I can't say I like using #PB_Any myself either now unless needed for specific situations(what ever they may be lol)
Below is a example project only to download. I set it up just like the original project I'm working on, but I used cheesy quick images I created in Gimp for this example. I created it with IceDesigner using #Constants
I will be removing the link at some point soon. THE DOWNLOAD DOES NOT INCLUDE ICEDESIGNER SOFTWARE just the test project folder
Run the program and click the Splash Screen image to continue to the next screen
https://mega.nz/file/E9sXyJKJ#_ZdCjTRIY ... NYiEPzqdIA
I have to say I agree now, I like the #Constants because if you use Enumeration/EndEnumeration it numbers them for you.blueb wrote: Wed Jul 03, 2024 1:44 pm IceDesign offers many ways to do things. Personally I don't like to use '#PB_Any'.
I find it adds a lot of 'fluff', although I have used it in some instances.
I prefer to use the '#Constants' option along with the 'Bind All Gadgets Events' flag, so that my events are isolated to my liking.
Just say'in![]()
I can't say I like using #PB_Any myself either now unless needed for specific situations(what ever they may be lol)
I have tested your EventDesigner and I like the idea, but it was kind of confusing to me. I don't know if you have updated it since I have tested it so I'd have to take a look at it again.mk-soft wrote: Wed Jul 03, 2024 4:26 pm That's how I see it too.
I also always use constants with named enumeration.
No unnecessary variables, clear assignment.
With my EventDesigner, I can then also call the function for events with a virtual table.
Below is a example project only to download. I set it up just like the original project I'm working on, but I used cheesy quick images I created in Gimp for this example. I created it with IceDesigner using #Constants
I will be removing the link at some point soon. THE DOWNLOAD DOES NOT INCLUDE ICEDESIGNER SOFTWARE just the test project folder
Run the program and click the Splash Screen image to continue to the next screen
https://mega.nz/file/E9sXyJKJ#_ZdCjTRIY ... NYiEPzqdIA
Last edited by Distorted Pixel on Fri Jul 05, 2024 9:09 pm, edited 3 times in total.
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? 
No one cares how much you know until they know how much you care

No one cares how much you know until they know how much you care
Re: Retrieve text from StringGadget that is inside ContainerGadget
Here on linux, normal gadgets mixed with a screen don't work (especially not overlapping). I think the screen continuously steals the focus from the StringGadget.
You also need a Flipbuffers() once per frame I think if you use a screen.
And you need a proper event handling, processing all events once per frame, not just one event per frame.
If all that doesn't apply to Windows (I don't know really) then forget about my post
You also need a Flipbuffers() once per frame I think if you use a screen.
And you need a proper event handling, processing all events once per frame, not just one event per frame.
If all that doesn't apply to Windows (I don't know really) then forget about my post
