Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
5 registered members (Dico, AndrewAMD, TipmyPip, NewbieZorro, Grant), 15,791 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Change multiple bmaps for buttons #284326
08/12/09 19:41
08/12/09 19:41
Joined: Aug 2009
Posts: 19
D
Dominator Offline OP
Newbie
Dominator  Offline OP
Newbie
D

Joined: Aug 2009
Posts: 19
I am making a card game in Lite-C. The player gets five cards to choose from. After they start I use a random number generator to decide what cards the player gets. Based on the number I want to change the button bmaps. I was wondering how I would change the bmaps without having to have lots of lines of codes.

Just tell me if you need to see my script and I can show you what I've already tried to do.

Re: Change multiple bmaps for buttons [Re: Dominator] #284328
08/12/09 20:03
08/12/09 20:03
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
At the manual:
pan_setbmap(PANEL*,var type,var num,BMAP*)

Re: Change multiple bmaps for buttons [Re: Widi] #284334
08/12/09 20:55
08/12/09 20:55
Joined: Aug 2009
Posts: 19
D
Dominator Offline OP
Newbie
Dominator  Offline OP
Newbie
D

Joined: Aug 2009
Posts: 19
The only problem with pan_setbmap is I have 25 different possibilities for what the bmap could be. I also need to change all three of the images for the button.

Also pan_setbmap does allow you to use any variables for the button number. This means I would have to do it for one button and then copy it three more times for the other buttons.

My fear is that having to do it this way will add lots of lines to my code.

If you don't understand what I mean tell me if you need to see what my script looks like.

Re: Change multiple bmaps for buttons [Re: Dominator] #284342
08/12/09 21:30
08/12/09 21:30
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
there's also pan_setbutton
pan_setbutton(PANEL*, var num, var type, var x, var y, BMAP* bmapOn, BMAP* bmapOff, BMAP* bmapOver, BMAP* bmapOverOff, void* functionClick, void* functionLeave, void* functionOver);
so you can change all the buttons at once, in one line of code

Re: Change multiple bmaps for buttons [Re: MrGuest] #284343
08/12/09 21:46
08/12/09 21:46
Joined: Aug 2009
Posts: 19
D
Dominator Offline OP
Newbie
Dominator  Offline OP
Newbie
D

Joined: Aug 2009
Posts: 19
I tried to do pan_setbutton but when I tried to compile it gave me an error.

Here is the code using pan_setbmap:

pan_setbmap(PlayersHand,3,1.0,SetUpTentOne);
pan_setbmap(PlayersHand,3,1.1,SetUpTentOne);
pan_setbmap(PlayersHand,3,1.2,SetUpTentOne);

could you help me change that so it uses pan_setbutton.

Re: Change multiple bmaps for buttons [Re: Dominator] #284347
08/12/09 22:16
08/12/09 22:16
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
well unfortunately you need to pass all the parameters

if you're trying to just shorten that just create a simple function

Code:
function change_card(var hand, int card, BMAP* bmp_card){
   pan_setbmap(hand, card, 1.0, bmp_card);
   pan_setbmap(hand, card, 1.1, bmp_card);
   pan_setbmap(hand, card, 1.2, bmp_card);
}

//then call 
change_card(freds_hand, 1, jack_heart);




Re: Change multiple bmaps for buttons [Re: MrGuest] #284367
08/13/09 01:12
08/13/09 01:12
Joined: Aug 2009
Posts: 19
D
Dominator Offline OP
Newbie
Dominator  Offline OP
Newbie
D

Joined: Aug 2009
Posts: 19
When I try and run this code it says crash in main

for (Count; Count <= 24; Count++)
{
if (Count <= 2)
{
CardCountUnc[Count] = 18;
}
else if (Count == 3) // Setup of unchanged card number array
{
CardCountUnc[Count] = 10;
}
else
{
CardCountUnc[Count] = 2;
}
}

Count = 0;

for (Count; Count <= 24; Count++)
{
CardCountCha[Count] = CardCountUnc[Count]; // Setup of changed card number array
}

random_seed(0);

Count2 = 0;
Count = 0;
CardNumberZero = 1;

for (Count2; Count2 <= 4; Count2++)
{
while (CardNumberZero == 1)
{
CardDrawNumber = rand() % 24; // Deal out players hand

for (Count; Count <= 24; Count++)
{
if (CardDrawNumber == Count)
{
if (CardCountCha[Count] > 0)
{
PlayerHand[Count2] = CardDrawNumber;
CardCountCha[Count]--;
CardNumberZero = 0;
// ChangeCardMap(CardDrawNumber,Count2);
PanelName = PanelChangeName(Count2);
CaPicture = FindCardPicture(CardDrawNumber);
ChangeCardMap(PanelName, CaPicture);
}
}
}
}
CardNumberZero = 1;
Count = 0;
}
}

function PanelChangeName(var Number)
{
STRING* PlayerCardPanelName;

if (Number == 0)
{
PlayerCardPanelName = "PlayerCardOne";
}
if (Number == 1)
{
PlayerCardPanelName = "PlayerCardTwo";
}
if (Number == 2)
{
PlayerCardPanelName = "PlayerCardThree";
}
if (Number == 3)
{
PlayerCardPanelName = "PlayerCardFour";
}
if (Number == 4)
{
PlayerCardPanelName = "PlayerCardFive";
}
return (PlayerCardPanelName);
}

function FindCardPicture(var Card)
{
BMAP* CardPicture;

if (Card == 1)
{
CardPicture = SetUpTentOne;
}

return (CardPicture);
}

function ChangeCardMap(Name,BMAP* Picture)
{
pan_setbmap(Name,3,1.0,Picture);
}

I am trying to pass the panel name and the name of the bmap to a function that will change the button based on this information. I would appreciate any help I can get.

Re: Change multiple bmaps for buttons [Re: Dominator] #284372
08/13/09 03:34
08/13/09 03:34
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
change your for loops to
Code:
for(Count = 0; Count <= 24; Count++){



instead of all the if else use switch
Code:
switch(Number){
   case 1:
       //do case 1
   break;
   case 2: etc...



A7 can't return strings too well, you'll need to set it inside the function
Code:
str_cpy(passed_string, result);



you shouldn't be getting the name of the panel, just return it's pointer


would it not be easier for you to have just 1 image of all the cards, then use a window to display the card, rather than having them all as seperate images?

and use [ code ] [/code] tags, makes it easier to read

hope this helps

Re: Change multiple bmaps for buttons [Re: MrGuest] #284376
08/13/09 05:25
08/13/09 05:25
Joined: Aug 2009
Posts: 19
D
Dominator Offline OP
Newbie
Dominator  Offline OP
Newbie
D

Joined: Aug 2009
Posts: 19
I have the different windows working now and they display the card pictures right. The last question I have is if I'm doing it in the shortest amount of lines possible.

PANEL* PlayersHand =
{
layer = 5;
window(180,790,140,218,GameCards2,382,0);
window(370,790,140,218,GameCards2,PictureX[1],0);
window(560,790,140,218,GameCards2,PictureX[2],0);
window(750,790,140,218,GameCards2,PictureX[3],0);
window(940,790,140,218,GameCards2,PictureX[4],0);
}

function main()
{
video_mode = 9;
video_screen = 1;

mouse_map = MousePointer;
mouse_mode = 4;
mouse_sync = 1;

set (PlayingBackground, SHOW);
set (OpponentsField, SHOW);
set (PlayersField, SHOW);
set (PlayersHand, SHOW);


}

function GameStart()
{

Count = 0;

for (Count; Count <= 24; Count++)
{
if (Count <= 2)
{
CardCountUnc[Count] = 18;
}
else if (Count == 3) // Setup of unchanged card number array
{
CardCountUnc[Count] = 10;
}
else
{
CardCountUnc[Count] = 2;
}
}

Count = 0;

for (Count; Count <= 24; Count++)
{
CardCountCha[Count] = CardCountUnc[Count]; // Setup of changed card number array
}

random_seed(0);

Count2 = 0;
Count = 0;
CardNumberZero = 1;

for (Count2; Count2 <= 4; Count2++)
{
while (CardNumberZero == 1)
{
CardDrawNumber = rand() % 24; // Deal out players hand

for (Count; Count <= 24; Count++)
{
if (CardDrawNumber == Count)
{
if (CardCountCha[Count] > 0)
{
PlayerHand[Count2] = CardDrawNumber;
CardCountCha[Count]--;
CardNumberZero = 0;
ChangeCardImage(CardDrawNumber,Count2);
}
}
}
}
CardNumberZero = 1;
Count = 0;
}

}
function ChangeCardImage(Number,HandNumber)
{
switch (Number)
{
case 0:
PictureX[HandNumber] = 135;
break;
case 1:
PictureX[HandNumber] = 263;
break;
case 2:
PictureX[HandNumber] = 382;
break;
}
}

Last edited by Dominator; 08/14/09 16:33. Reason: Figured out how to make ChangeCardImage more efficient

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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