1 registered members (TipmyPip),
18,388
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
buttons...
#294106
10/16/09 11:21
10/16/09 11:21
|
Joined: Apr 2009
Posts: 248 Philippines
seecah
OP
Member
|
OP
Member
Joined: Apr 2009
Posts: 248
Philippines
|
Hi, I have a looping function to display the buttons on my level selector.. I need to do it in loop since I have 25 ( 5x5 arrangement) levels and it would add so much lines on my code if I'll do it one by one.. But my problem is assigning a function on each buttons since they will execute variable functions.. Eg. when button1 is clicked it will execute on_level1(), button2-on_level2().. and so on I've tried to use snippets like this, inside my for loop assume that str_func is initialize as str_func = str_create("on_level");
level_ID = row + (column * 5);
str_for_int(func_buffer, level_ID);
str_cat(str_func, func_buffer);
and then use str_func inside the button function pan_create("button(0,0,bmap_levelimage_press1,bmap_levelimage_def1,bmap_levelimage_press1, str_func, NULL, NULL);", 10);
but really funny since I didn't notice that button function should be function name and can't understand what's inside the string.. Is there any dynamic way of implementing that process? Please advise.. Thanks...
Can't is not an option™
|
|
|
Re: buttons...
[Re: seecah]
#294110
10/16/09 11:46
10/16/09 11:46
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
There is ALWAYS a way, finding it is half the fun... and a good reason for hair-loss.
Ive got a couple of ideas in mind, but the best one involves all the buttons on a single panel.
Is this allowable?
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: buttons...
[Re: EvilSOB]
#294111
10/16/09 11:49
10/16/09 11:49
|
Joined: Apr 2009
Posts: 248 Philippines
seecah
OP
Member
|
OP
Member
Joined: Apr 2009
Posts: 248
Philippines
|
I even got 10+ hairs on my head..  Actually I'm storing the panels inside a double array... arr_levels[column][row] = pan_create("button...").. Will it help with your best idea?
Can't is not an option™
|
|
|
Re: buttons...
[Re: seecah]
#294112
10/16/09 12:16
10/16/09 12:16
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Not really, it makes the 'more difficult to explain' version more necessary. Unless you are storing them in the array to try to make the selection work... The simple way would have worked roughly like this. I dont know if you are aware, but when a button is clicked and calls its function, it is also passing a couple of parameters to that function. It is passing its button number within the panel, and a pointer to the panel itself. So if all the buttons were in one panel, just assign all the buttons to ONE function, and have that function look at the button number, and call whichever "on_levelX()" is required. Easy, see? (if you want, I can elaborate further)But sticking with a multi-panel single-button-per-panel menu, weve gotta go my other way. When you are building your panels, you need to add a line after the pan create, to modify a value.
arr_levels[column][row] = pan_create("button..., on_level_button, NULL, NULL);", 10);
(arr_levels[column][row]).skill_x = level_ID; //or row+(column*5)
and the function that all the buttons will call is this
function on_level_button(var butt_num, PANEL* pan)
{
var level_ID = pan.skill_x;
if (level_ID==1) on_level1();
else if(level_ID==2) on_level2();
else if(level_ID==3) on_level3();
else if(level_ID==4) on_level4();
else if(level_ID==5) on_level5();
else if(level_ID==6) on_level6();
... etc
}
Get what I mean?
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: buttons...
[Re: EvilSOB]
#294117
10/16/09 13:07
10/16/09 13:07
|
Joined: Apr 2009
Posts: 248 Philippines
seecah
OP
Member
|
OP
Member
Joined: Apr 2009
Posts: 248
Philippines
|
I really like your first approach and honestly I don't know that idea during a button clicked event (still a lot to learn in Lite-C :)),if I knew earlier I would take that approach but anyhow I'll implement this during code optimization but for now since I have no time for a demo to make manually 25 buttons in one panel with different bitmaps each row I'll take your 2nd option.. So bad, I never thought of applying a skill on a panel which I think only entities and particles have..  I still need to go deeper in Lite-C for me to know that kind of stuff.. Thanks EvilSOB.. again my savior.. super thank you, I hope I can return a favor someday.. Have more power and knowledge.. 
Can't is not an option™
|
|
|
Re: buttons...
[Re: seecah]
#294191
10/16/09 21:19
10/16/09 21:19
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
no problem.
you really should take a look in the aTypes.h file in the gstudio/includes folder. it shows all the structures of all the object types. Many parts of which arent in the manual.
See you about...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: buttons...
[Re: EvilSOB]
#294421
10/19/09 03:49
10/19/09 03:49
|
Joined: Apr 2009
Posts: 248 Philippines
seecah
OP
Member
|
OP
Member
Joined: Apr 2009
Posts: 248
Philippines
|
Hi EvilSOB, I have just tried the 2nd idea that you give but it seems that skill is not a member of the panel since it gives me an error Error in 'menu.c' line 106: 'skill' : is not a member of 'PANEL' < arr_levels[column][row].skill99 = row + (column * 5); >
and even using (arr_levels[column][row]).skill1 = row + (column * 5); still not works for me..
Last edited by seecah; 10/19/09 03:56.
Can't is not an option™
|
|
|
Re: buttons...
[Re: seecah]
#294472
10/19/09 11:49
10/19/09 11:49
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
ah, no. there is no skill number, I meant LITERALLY skill_x
it has skill_x, skill_y, and skill_z, not numbers.
Hope this clears things up.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: buttons...
[Re: EvilSOB]
#294488
10/19/09 13:55
10/19/09 13:55
|
Joined: Apr 2009
Posts: 248 Philippines
seecah
OP
Member
|
OP
Member
Joined: Apr 2009
Posts: 248
Philippines
|
aaaaahhhhhh.. i thought x stands for 1-100.. ^^.. but to think I choose to implement the first approach and fortunately it's done.. I was just thinking that since I have to spend time on it, i'd rather code it with the most efficient way.. But then again, I stand corrected for panels we can use skillx-skillz..
Thank you so much!!!!
Can't is not an option™
|
|
|
Re: buttons...
[Re: seecah]
#294815
10/21/09 12:17
10/21/09 12:17
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Hey, code whichever way you want, its your baby, not mine.
You can see which way will fit better into th 'bigger picture" than me.
Im just giving you options to choose from.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|