Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,014 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
can not use variables for panel positions. #432583
11/08/13 17:25
11/08/13 17:25
Joined: Nov 2006
Posts: 497
Ohio
xbox Offline OP
Senior Member
xbox  Offline OP
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
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.

Last edited by xbox; 11/08/13 17:26.
Re: can not use variables for panel positions. [Re: xbox] #432584
11/08/13 17:38
11/08/13 17:38

M
Malice
Unregistered
Malice
Unregistered
M



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.

Last edited by Malice; 11/08/13 17:47.
Re: can not use variables for panel positions. [Re: ] #432586
11/08/13 17:55
11/08/13 17:55
Joined: Nov 2006
Posts: 497
Ohio
xbox Offline OP
Senior Member
xbox  Offline OP
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
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

Re: can not use variables for panel positions. [Re: xbox] #432587
11/08/13 18:10
11/08/13 18:10

M
Malice
Unregistered
Malice
Unregistered
M



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

Last edited by Malice; 11/08/13 18:13.
Re: can not use variables for panel positions. [Re: ] #432588
11/08/13 18:15
11/08/13 18:15
Joined: Nov 2006
Posts: 497
Ohio
xbox Offline OP
Senior Member
xbox  Offline OP
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
Okay, thanks a lot for your help. Trying to be like the cool kids, grin lol. I found that way too hilarious.

Re: can not use variables for panel positions. [Re: xbox] #432590
11/08/13 18:29
11/08/13 18:29
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
"." 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.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: can not use variables for panel positions. [Re: xbox] #432594
11/08/13 21:26
11/08/13 21:26
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
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.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: can not use variables for panel positions. [Re: WretchedSid] #432596
11/08/13 21:49
11/08/13 21:49

M
Malice
Unregistered
Malice
Unregistered
M



@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


Last edited by Malice; 11/08/13 21:56.
Re: can not use variables for panel positions. [Re: ] #432597
11/08/13 22:09
11/08/13 22:09
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
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)


Last edited by JustSid; 11/08/13 22:12.

Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: can not use variables for panel positions. [Re: WretchedSid] #432599
11/08/13 22:56
11/08/13 22:56

M
Malice
Unregistered
Malice
Unregistered
M



Wow - Ok this is going to be new. grin

Page 1 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1