GUI CreateWindow() function

Started by Sebastian, Jun 05, 2018, 02:28 PM

Previous topic - Next topic

Sebastian

Hey there!

I'm looking forward for an overall function when creating GUI elements;
something like:
CreateWindow( size, colour, pos, text, textcolour, fontsize )
I tried my luck, but for some reason, it doesn't show up at all...
function qGUI( type, ... )
{
    switch( type.tostring() )
    {
        case "window":
        {
            local   q = GUIWindow(),
                    size = vargv[0],
                    colour = vargv[1],
                    pos = vargv[2],
                    text = vargv[3].tostring(),
                    textcolour = vargv[4],
                    fontsize = vargv[5];
                   
            q.Size = size;
            q.Colour = colour;
            q.Pos = pos;
            /* GENERAL */ q.FontFlags = ( GUI_FFLAG_BOLD );
            /* GENERAL */ q.RemoveFlags( GUI_FLAG_WINDOW_RESIZABLE | GUI_FLAG_WINDOW_CLOSEBTN );
            q.Text = text;
            q.TextColour = textcolour;
            q.FontSize = fontsize;
       
        break;
        }
}

If I do it in the classic way (one-by-one function for every setting) it will work.
What's going on ? How can I make it work ?

NicusorN5

It should work if you use GUIWindow() with the parameters inside the constructor.

Sebastian

#2
Quote from: Athanatos(^_^) on Jun 05, 2018, 03:24 PMIt should work if you use GUIWindow() with the parameters inside the constructor.

I remember trying before, but they were not working properly. That's why I'm looking for an alternative.
But I will try again, and come with an edit.

EDIT: GUI Window works with full structure. GUI Label not.

.

#3
If something fails and you don't know why. Wrap it in a try/catch lock and print the error to chat/console. In fact, all your event functions should be wrapped in something like that. Otherwise, you're forced to look into a text file just like a primitive. And things get even worse if that log file is buffered. Because you have to stop the game to flush the buffer. Although logs are not usually buffered. Otherwise you risk loosing information if there's a crash. But who knows.

Secondly, probably off-topic but that `switch( type.tostring() )` code is welcoming bad practice. Never convert to string. If `type` is not a string. Then make the code complain about it. Just say `hey dude. I know you think you can be versatile here. but one of these days, you're gonna change something in this type and I'm not gonna get "window" in return. and then you shall witness my wrath. *smiley-face*`.

And as a nitpick, that `break;` is usually after the scope. like:
switch (x) {
    case y: {
        //...
    } break;
}

Because a case inside a switch can (should? I suppose it depends on the language) only have one statement. And by using curly braces. You turn multiple statements into a single one. And if you declare variables inside that statement you basically forced to use curly braces. Which is why, after the curly braces (which are seen as a single statement) comes the break; which is seen as a separate statement. The switch case acts a bit differently than a loop.
.

Sebastian

I just printed all the values my function was receiving, and they needed to be split one by one, like colour.R colour.B colour.G in order to load properly. So that was my mistake.



About the switch( type.tostring() ) you are right. But don't know what to say about the "break;" thing you also elaborated. Maybe in Squirrel it is not mattering that much ? I've using it like this, without scopes, and didn't face problems :/

.

Quote from: Sebastian on Jun 05, 2018, 04:29 PMAbout the switch( type.tostring() ) you are right. But don't know what to say about the "break;" thing you also elaborated. Maybe in Squirrel it is not mattering that much ? I've using it like this, without scopes, and didn't face problems :/

And you never will. Because it works like that too. I said, they're usually added after the braces as a separate statement. In fact you can put that break; in any number of nested scopes, and it still throws you out of the switch.

switch (x) {
case y: {
{
{
{
{
break;
}
}
}
}
}
}
.

Sebastian

Everything fixed, so I'm marking this as Solved.
If you guys need such a function >check this link<

=RK=MarineForce

CreateWindow( size, colour, pos, text, textcolour, fontsize )

can some one tell me how to use this i don't understand

size colour pos text textcolour fontsize i don't know about this can u tell me about this plz
Try to UnderStand ME!