can not use variables for panel positions.

Posted By: xbox

can not use variables for panel positions. - 11/08/13 17:25

I would like to place buttons and panels on the screen in locations based on the screen resolution, but when I try something like the following I get a syntax error.
Code:
PANEL* menuPan={
pos_x = (sys_metrics(0) - bmap_width(background))/ 2;
pos_y = (sys_metrics(1) - bmap_height(background))/ 
...}

but if I do the math myself and just put the answers in, it works fine. I can't do this though because the screen resolution may be different on other pc's.

Edit: Yes the bmap background is defined before the Panel.
Posted By: Anonymous

Re: can not use variables for panel positions. - 11/08/13 17:38

You have to do it in a function after the panel setup.
Panel define can not except variables because they are not set when the panel is created.. Use constants in define and modify with vars in functions after the define.
EDIT-> Also you can not use even simple math operations in a panel define.

Code:
PANEL* pan_this ={
....
pos_x = 1;
}

function main()
{
....
pan_this->pos_x =(sys_metrics(0) - bmap_width(background))/ 2;

....
}



EDIT -> JCL addressed this issue in one of the ask the dev or bug hunt threads and he explains better then me. I couldn't find it quickly to post a link. Hate looking for stuff on this forum, its a blackhole of good information.
Posted By: xbox

Re: can not use variables for panel positions. - 11/08/13 17:55

Okay, I understand the idea behind this now, and I have it working correctly, But what is the -> for. I've seen it in c++ programming (something I'm very familiar with) but I don't know what it is or does, seems like an alternative to the '.' like pan_this.pos_x
Posted By: Anonymous

Re: can not use variables for panel positions. - 11/08/13 18:10

It is just that for the most part in LiteC. I may use it wrong as a matter of form but it does replace '.' and pan_this.pos_x is correct. I believe there is information in manual about using it, but I think '.' is for members and '->' for flags in this form. Tell you the truth I see the experts here use it a lot and so I do - Just trying to be like the cool kids LOL. cool
Posted By: xbox

Re: can not use variables for panel positions. - 11/08/13 18:15

Okay, thanks a lot for your help. Trying to be like the cool kids, grin lol. I found that way too hilarious.
Posted By: Superku

Re: can not use variables for panel positions. - 11/08/13 18:29

"." normally only works on objects (/ instances of a struct), "->" is for pointers:

VECTOR temp; temp.x = 10;
VECTOR* temp; temp->x = 10;

Lite-C detects automatically whether "." is correct or should be "->", but you can deactivate this help with some pragma-define if you want to.
Posted By: WretchedSid

Re: can not use variables for panel positions. - 11/08/13 21:26

Originally Posted By: xbox
I've seen it in c++ programming (something I'm very familiar with) but I don't know what it is or does

I highly doubt your statement if you don't know the difference between the "." and "->" operator.

First one is member access, second one is member access by dereferencing a pointer. Lite-C allows you to substitute -> with ., that doesn't make it nice syntax though, just eased the transition from C-Script.
Posted By: Anonymous

Re: can not use variables for panel positions. - 11/08/13 21:49

@Superku What would I have to do to deactivate it? Seems like an easy step to help learn how to move out of the safety net of Lite-C.

@Justsid so I should use it for anything create like this -part*

BMAP*
SOUND*
PANEL*
all use -> for dereferencing to the data

Posted By: WretchedSid

Re: can not use variables for panel positions. - 11/08/13 22:09

Code:
#define PRAGMA_POINTER



And yes, every member access through a pointer needs to dereference the pointer, which is what the -> operator is doing. Alternatively, you can also use something like (*ptr).member, which is essentially the same thing: Dereference the pointer, access the member.

Anyhow, PRAGMA_POINTER will also require you to make more changes. Something like this for example doesn't work anymore:
Code:
VECTOR temp;
vec_set(temp, nullvector);



The signature of vec_set() is pretty clear, the first argument has to be a pointer, but temp isn't in this case. Instead you have to use the reference operator & to get the pointer to temp:
Code:
VECTOR temp;
vec_set(&temp, nullvector);



Similarly:
Code:
vec_set(my.x, nullvector); // Wrong
vec_set((VECTOR *)(&my->x), nullvector); // Right. Also note the explicit cast, because &my->x gives you a pointer to a var)

Posted By: Anonymous

Re: can not use variables for panel positions. - 11/08/13 22:56

Wow - Ok this is going to be new. grin
Posted By: xbox

Re: can not use variables for panel positions. - 11/08/13 23:48

Only backing myself up here, I, being 22 years old, have 13 years of c++ experience. Granted only 4 of those are object oriented, which was taught in college and unfortunately we never learned the -> operator. Just showing where that previous statement came from.

Also, I'm with @Malice on this topic. I'm excited to put this to good use and experiment with it. grin
Posted By: WretchedSid

Re: can not use variables for panel positions. - 11/12/13 03:25

Originally Posted By: Malice
Wow - Ok this is going to be new. grin

Welcome to the world of programming mate tongue

Originally Posted By: xbox
Only backing myself up here, I, being 22 years old, have 13 years of c++ experience. Granted only 4 of those are object oriented, which was taught in college and unfortunately we never learned the -> operator. Just showing where that previous statement came from.

So? I'm 21 years old and have way less C++ experience. Do you really want to start this pissing contest now?
Truth be told, if you worked with C++ for 13 years and only figured out that you can use OOP after 9 of them, you did something substantially wrong. Either you didn't know the language (which is still my bet), or you deliberately ignored one of the core idioms the language has to offer. If you never heard about the -> operator, well, I'm sorry, but then you haven't worked with C++. Heck, it's overloaded in most std::iterator<> subclasses and definitely in the ones provided by all significant containers in the STL.

Sorry, but someone who doesn't know the core language idioms, doesn't know the language.
Posted By: Anonymous

Re: can not use variables for panel positions. - 11/12/13 17:08

@JustSid - About time I moved out of this Lite-C trap and away from this very dead environment . I've hobbled myself here and I can learn to write code without a school to teach me as long as I use a little time and a little Google. Thanks Sid
© 2024 lite-C Forums