Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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), 629 guests, and 2 spiders.
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 3 1 2 3
row of panels / array issue (solved) #273528
06/23/09 10:43
06/23/09 10:43
Joined: Oct 2008
Posts: 67
C
Crypton Offline OP
Junior Member
Crypton  Offline OP
Junior Member
C

Joined: Oct 2008
Posts: 67
DONE::

I need to achieve this:
I want to show bullet images in a row according to bullets I have. Like an indicator how much bullets I have in a cartridge.

I tried this way. Engine compiles but nothing shows up. Definitely something missing here.


BMAP* hud_bullet = "bullet_ico.png"; //load an image

var bullets = 5; //bullet counter
PANEL* bul_panel[9]; //predefine panels' pointers? (9 because 9 is the max "bullet image count" in the game)

//try to create panels here and display them
function reload()
{
var a;
//make as many icons as I have bullets:
for (a=0; a < bullets; a+=1)
{
PANEL* panel = pan_create(NULL, 101); //Create a panel in runtime
//panel.layer = 101;
panel.bmap = hud_bullet; //(bmap_create("frame.pcx");
panel.pos_x = 366 - 7*a; //Position it according to "for loop" state.
set(panel, SHOW); //display the current created panel
bul_panel[a] = panel; //trying to save current panel pointer to predefined pointer, so I could manage the specific one later on, like: reset(bul_panel[3], SHOW); So the 3-rd bullet is gone, when it's shot etc.
wait(1);
}
}

Any Idea how to fix/create that?

DONE::

-----------------------------------------------
Array issue:

My problem is I don't get that value I try to access.
f.i. I have defined:

var arr[2][2];
//set values:
arr[0][0] = 5;
arr[0][1] =10;

and I want to get certain array value:

add_on = arr[0][g_type]; //g_type is whether 0 or 1.

I don't get the value... add_on is 0 when it should be 10 when g_type is f.i 1.

Last edited by Crypton; 06/26/09 20:32.

New into Gamestudio and eager to learn it..
Stuff and games done in 2D: LINK
Re: Creating row of panels in runtime [Re: Crypton] #273537
06/23/09 11:25
06/23/09 11:25
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Educated guess (plus some optimisation)...
Code:
function reload()
{
   var a;   for (a=0;  a < bullets; a+=1)
   {
      bul_panel[a] = pan_create(NULL, 101);       // Create this bullet-panel in runtime
      bul_panel[a].bmap = hud_bullet;             // bmap_create("frame.pcx");
      bul_panel[a].size_x = hud_bullet.width;     // <<< Important addition
      bul_panel[a].size_y = hud_bullet.height;    // <<< Important addition
      bul_panel[a].pos_x = 366 - 7*a;             // Position it in "clip"
      set(bul_panel[a], SHOW);                    // display "this" bullet-panel
      wait(1);
   }
}

Your panels are being created with a width & height of 0 by 0.
The above code should fix that.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Creating row of panels in runtime [Re: EvilSOB] #273558
06/23/09 12:32
06/23/09 12:32
Joined: Oct 2008
Posts: 67
C
Crypton Offline OP
Junior Member
Crypton  Offline OP
Junior Member
C

Joined: Oct 2008
Posts: 67
hmm didn't work.
I tried without the array in predefinition:

PANEL* bul_panel;

and then trying to create the panel in runtime into it. (without for loop etc, just like one run). Nothing.

I even tried to crash my game through this function testing if the bul_panel[a] existsed or not. It didn't close program when I tested NULL and it didn't close when I tested bul_panel in the "else" part (if it isn't NULL then else indicates that pointer was given)
Code:
for (a=0;  a < bullets; a+=1)
   {
      bul_panel[a] = pan_create(NULL, 101);
      if (bul_panel[a] == NULL)
      {
         sys_exit("blabla");
      }else{
         sys_exit("blabla");
    [...]



So I'm guessing the pan_create doesn't do its job ?

Also just to think, when i give panel bmap wouldn't it take it's size according to that image? Also I didn't get width and height parameters coloured, maybe another manual flaw or LiteC doesn't recognise them?


New into Gamestudio and eager to learn it..
Stuff and games done in 2D: LINK
Re: Creating row of panels in runtime [Re: Crypton] #273571
06/23/09 13:06
06/23/09 13:06
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Are you doing this in c-script, or lite-c?
If you are using c-script, you may need to use bmap_height(BMAP*) and bmap_width(BMAP*)
instead of hud_bullet.width etc.
But read further down as there is a cleaner work-around...
Please bear in mind, I am primarily Lite-C, so my c-script skills are low...

Firstly, put your global definitions back to
var bullets = 5;
PANEL* bul_panel[9];

and try changing the pan_create to be
bul_panel[a] = pan_create("flags=SHOW;", 101);

The panels dont automatically pick up the size of the bmap, UNLESS the bmap
name is supplied in the creation string.
eg
Code:
var bullets = 5;
PANEL* bul_panel[9];

function reload()
{
   var a;   for (a=0;  a < bullets; a+=1)
   {
      bul_panel[a] = pan_create("bmap=hud_bullet; flags=SHOW;", 101); 
      bul_panel[a].pos_x = 366 - 7*a;        // Position it in "clip"
      wait(1);
   }
}



Unfortunately, your current NULL-test will always fail ATM, because when you define
the array with PANEL* bul_panel[9];, you can almost be sure its contents arent NULL,
even though there isnt ANY valid panel pointers in there.
You need to flush them clean at startup in main, or like this.
Code:
PANEL* bul_panel[9];
void bul_panel_startup()  {  var i;  for(i=0, i<9; i++)  bul_panel[i]=NULL;  }


Then your NULL checking would work, ASSUMING then any time you ptr_remove a bullet,
you set that array element to NULL straigt away.
eg
Code:
...
ptr_remove(bul_panel[xx]);
bul_panel[xx] = NULL;
...




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Creating row of panels in runtime [Re: EvilSOB] #273579
06/23/09 14:52
06/23/09 14:52
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline
User
Gordon  Offline
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
PNG files are note supported. Well at least not in this area based on the manual (unless it is wrong here)

"The image must be in PCX, BMP, or TGA format."

PGN is supported for sprites and textures but it is not recommended as it is loaded by direct X and can be lost during run-time.

again from the manual

"PNG images behave like TGA images, but are not recommended because they are loaded not by the engine, but by the DirectX library, and are not guaranteed to be automatically restored when the video device gets lost. This means that they can lose their content f.i. when a fullscreen application is minimized."

hope this helps


Our new web site:Westmarch Studios
Re: Creating row of panels in runtime [Re: Gordon] #273753
06/24/09 09:56
06/24/09 09:56
Joined: Oct 2008
Posts: 67
C
Crypton Offline OP
Junior Member
Crypton  Offline OP
Junior Member
C

Joined: Oct 2008
Posts: 67
Yes I am aware og PNG's unsupport'ness :P. The thing I use PNGs is because my image editor doesn't seem to save alpha channel in tga format, even if I save it in 32 bit :S.
____________
omg, now I got it worked and in somewhere totally different place.
the called function reload() was the last function in function main() to be called. I changed it's location after the level_load(""); and then icons popped out!

Was here something I missed/might have been known ?!
Code:
function main()
{
   video_mode = 6;
   //vec_set(sky_color,vector(1,1,1));
   level_load(""); // load an empty level
   wait(2);
   
   p_tele_light.pos_x = p_teleport.pos_x;
   p_tele_light.pos_y = p_teleport.pos_y;
   light_change();
   
   reload(); //GHANGED IT HERE
   
   while(1)
   {
      health_upd();
      card_upd();
   wait(1);
   }
   
   //reload() //WAS HERE BEFORE!

}



Last edited by Crypton; 06/24/09 12:24.

New into Gamestudio and eager to learn it..
Stuff and games done in 2D: LINK
Re: Creating row of panels in runtime [Re: Crypton] #273798
06/24/09 12:59
06/24/09 12:59
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline
User
Gordon  Offline
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
Try using GIMP for your image editor. Works well for me and it is free. Alternatively you can save as bmp with solid black where you want transparent, then set the overlay flag. As for why reload worked after level_load it is probably that level_load resets the direct X device and thus clears the png images loaded by direct x.


Our new web site:Westmarch Studios
Re: Creating row of panels in runtime [Re: Gordon] #273804
06/24/09 13:30
06/24/09 13:30
Joined: Oct 2008
Posts: 67
C
Crypton Offline OP
Junior Member
Crypton  Offline OP
Junior Member
C

Joined: Oct 2008
Posts: 67
mm filetype didn't make any change though. Even tga's weren't shown when reload() was the last function in main() (and still after level_load).

But hey I got it work. Thanks for the detailed information!


New into Gamestudio and eager to learn it..
Stuff and games done in 2D: LINK
Re: Creating row of panels in runtime [Re: Crypton] #273806
06/24/09 13:55
06/24/09 13:55
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
You have a while(1) loop in the main before the reload, so the line with the reload was never reach

Last edited by Widi; 06/24/09 13:55.
Re: Creating row of panels in runtime [Re: Widi] #273823
06/24/09 15:35
06/24/09 15:35
Joined: Oct 2008
Posts: 67
C
Crypton Offline OP
Junior Member
Crypton  Offline OP
Junior Member
C

Joined: Oct 2008
Posts: 67
...


New into Gamestudio and eager to learn it..
Stuff and games done in 2D: LINK
Page 1 of 3 1 2 3

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