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
Array of strings or bmaps #437997
03/04/14 18:11
03/04/14 18:11
Joined: Nov 2006
Posts: 497
Ohio
xbox Offline OP
Senior Member
xbox  Offline OP
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
Hi all, i am having a noobish problem.

I have one panel that i want to change the bmap value at runtime.

Instead of defining 10 different bmaps with 10 names, I'd like to just run a loop to access the bmap from an array. I originally defined the array like this:
Code:
BMAP* pages[10] = {"page1.bmp", "page2.bmp", ..., "page10.bmp"};


but the script will not compile due to a syntax error.
So instead I tried:
Code:
STRING* pages[10] = {"page1.bmp", "page2.bmp", ..., "page10.bmp"};


and again, the script did not complile due to a syntax error.
The problem seems to be the double quotes need to be single quotes because when i changed them, it compiled however the bmap was not changed.
For some reason using this line:
Code:
story.bmap=pages[0];

the bmap is not displayed

I really want to use an array to make my life easier grin but I don't know why it's not working.

Re: Array of strings or bmaps [Re: xbox] #438007
03/04/14 19:06
03/04/14 19:06
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
If your pages have always the format "page#.bmp", you can do it programmatically like this:

Code:
void loadPage (PANEL* p, int index)
{
	if (p != NULL)
	{
		if (p->bmap != NULL) {
			bmap_purge(p->bmap);
			p->bmap = NULL;
		}
		
		char filename [256];
		sprintf(filename, "page%d.bmp", index);
		
		p->bmap = bmap_create(filename);
	}
}



The interpretation of

Code:
BMAP* b = "helloworld.tga";



is a Lite-C custom feature and does not work for arrays. If you want to achieve that, you could do the following:

Code:
#define NUM_BMAPS 10
BMAP* bmapArray [NUM_BMAPS];

void bmapArray_startup ()
{
	int i;
	for (i = 0; i < NUM_BMAPS; i++)
	{
		char filename [256];
		sprintf(filename, "page%d.bmp", i);
		
		bmapArray[i] = bmap_create(filename);
	}
}



to fill the array on game startup (_startup functions are always call on engine startup!).

If you want to have an array of strings, you could do the following with a TEXT object:

Code:
TEXT* pageFilenames = {
  string ("page0.bmp", "page1.bmp", "page2.bmp", "page3.bmp");
}



and access it with e.g.

Code:
(pageFilenames->pstring)[1] ( == "page1.bmp")



I hope you get the idea wink

Last edited by HeelX; 03/04/14 19:07.
Re: Array of strings or bmaps [Re: HeelX] #438020
03/04/14 21:42
03/04/14 21:42
Joined: Nov 2006
Posts: 497
Ohio
xbox Offline OP
Senior Member
xbox  Offline OP
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
Thanks for the fast response. laugh

I never thought to do it the first way, but it seems to be the most logical so that's what I want to do, however I've run into a bit of an issue.

I went through the code to understand it, and I know what is supposed to happen, however the results that i'm getting say otherwise. First off, sprintf is not a valid function (i know it is in c++ but apparently not this engine, without external files) so I thought maybe you meant str_printf but that might be what's causing this issue. Right after that call I can an error saying invalid function arguments. With that, I decided to print the string on screen to see what was coming from str_printf and it is just random letters and symbols, hence why the bmap is not loading. Of course, as soon as I posted a response, I figured it out. The problem was in fact str_printf. All I had to do was include stdio.h, change it back to sprintf and it works. Thanks man. laugh

Last edited by xbox; 03/04/14 21:45.

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

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