Gamestudio Links
Zorro Links
Newest Posts
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
4 registered members (degenerate_762, AbrahamR, AndrewAMD, ozgur), 667 guests, and 8 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
Changing BMAP's dynamically #446160
10/07/14 09:29
10/07/14 09:29
Joined: Aug 2014
Posts: 57
Y
Yking Offline OP
Junior Member
Yking  Offline OP
Junior Member
Y

Joined: Aug 2014
Posts: 57
Hello everyone,

I currently have a minor problem, but I can't find any solution for it, maybe it is some kind of Beginners-Problem.

Let's assume I want a game with 100 items in it, I want to code in a non-copy-paste way. I made an Array for Itemnames and one for BMAP's. So now I can use the Index of my array as an "ID-code". Item[1] has Picture[1], that sounds logical to me.

So, my Arrays are global, I want to access them easily, I created a function to write some data into my index-numbers, also not a problem (and when I test them via printf(xxx); then I get the correct information aswell (Name, path to the picture).

Okay, here is the problem:
I am calling another function (it comes last), which should use a panel to display the BMAP. Unfortunately it does not work.

It all looks like this:
Quote:

STRING* item_name[100];
BMAP* item_bmap[100];

function make_items()
{
item_name[1] = "Potion";
item_bmap[1] = "items/drink/potion.tga";
}

function display_item()
{
PANEL* test = {layer = 4; flags = VISIBLE; pos_x = 200; pos_y = 200; bmap = item_bmap[1];}
}


The error is, that the program doesnt know what this Bitmap is, so I thought I need to declare some other (empty) Bitmap first to avoid errors, and then just before I want to display it, I change the bitmap-path, so I get the BMAP I want.
Here is what I came up with:

Quote:

STRING* item_name[100];
BMAP* item_bmap[100];
BMAP* placeholder = "items/empty.tga";

function make_items()
{
item_name[1] = "Potion";
item_bmap[1] = "items/drink/potion.tga";
}

function display_item()
{
placeholder = item_bmap[1];
printf("placeholder ");
PANEL* test = {layer = 4; flags = VISIBLE; pos_x = 200; pos_y = 200; bmap = placeholder;}
}


To sum it up: The placeholder gets overwritten and for debugging-purposes I do a "printf()".
The message I get on my screen is absolutely right: Its the path to the .tga that I want to have BUT
my panel still gets the "placeholder-Bitmap".

So I think, my question is: How do I correctly change the bitmap of my panel dynamically, or is there a better solution for my problem?

Thanks for all help in advance laugh

Re: Changing BMAP's dynamically [Re: Yking] #446161
10/07/14 09:45
10/07/14 09:45
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Why do you declare the panel inside a function?
Either create it globally as well or dynamically via pan_create() - or alternatively use draw_quad to draw your bitmaps (above all other panels, though).
You can change the bmap of a panel at any time like this:
pnl_test.bmap = item_bmap[1];
(Btw. indices start at 0, not 1, but I guess you know that.)
You can declare the panel without a SHOW (not VISIBLE) flag and only set it when you actually want to see its content.


"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: Changing BMAP's dynamically [Re: Yking] #446162
10/07/14 09:57
10/07/14 09:57
Joined: Nov 2005
Posts: 204
Bavaria
HellThunder Offline
Member
HellThunder  Offline
Member

Joined: Nov 2005
Posts: 204
Bavaria
Try this to initialize a STRING or a BMAP.

Code:
function make_items()
{
item_name[0] = str_create("Potion");
item_bmap[0] = bmap_create("items/drink/potion.tga");
}



Please start counting with 0. If you have an array with a length of 100 - the first variable is always 0 and the last one 99. Sounds a little bit strange but do it to prevent memory leaks.


You don't have to use the directory every time if you want to create a new bmap.

Use
Code:
#define PRAGMA_PATH ".\\items\\drink";


at the beginning of your script. Then you can use every file inside this folder by typing just the name of it.

Code:
item_bmap[0] = bmap_create("potion.tga");



Regards,
HellThunder


Create your own JRPG and join our community: https://www.yrpgtoolkit.com
Re: Changing BMAP's dynamically [Re: Yking] #446186
10/07/14 19:27
10/07/14 19:27
Joined: Aug 2014
Posts: 57
Y
Yking Offline OP
Junior Member
Yking  Offline OP
Junior Member
Y

Joined: Aug 2014
Posts: 57
Thanks for all the help, I got it working now laugh .

This panel I talked about is Debug-Only, just so I can see if the bmap really changes.
I didn't use the index 0 because I reserved that for an "no item state" laugh

I used HellThunders method of doing
Quote:

item_name[0] = str_create("Potion");
item_bmap[0] = bmap_create("items/drink/potion.tga");


and used Superkus
Quote:

pnl_test.bmap = item_bmap[1];

to change the panelbmap... and it worked grin !

Excellent help, you guys laugh !

Re: Changing BMAP's dynamically [Re: HellThunder] #446191
10/07/14 22:46
10/07/14 22:46
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Originally Posted By: HellThunder
Please start counting with 0. If you have an array with a length of 100 - the first variable is always 0 and the last one 99. Sounds a little bit strange but do it to prevent memory leaks.

This has nothing to do with memory leaks. If you don't touch the first element in an array, it won't do anything. It does decrease readability and maintainability, especially for outside developers, but tough luck for them I suppose.

The real reason you start with index 0 is because otherwise you are simply wasting an element. And are probably overwriting memory at the end.

The reason why it is 0 is also not strange in any way shape or form, the index is simply an offset into the array. The first element logically has the offset 0 because it is at the very beginning.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com

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