Problem mit Item-Panel.(GER&ENG)

Posted By: HellThunder

Problem mit Item-Panel.(GER&ENG) - 12/05/12 12:22

Code:
GERMAN:


Hallo. Ich versuche gerade ein dynamisches Item Menü bzw. eine Anzeige zu basteln, die mir Items auflistet. Hierfür möchte ich einmal ein var Array und ein String Array verwenden.
Die Werte sollen über ein Panel angezeigt werden.
Mein Problem ist folgendes: Mit der Verwendung der oben angegebenen Arrays, werden mir keine Werte bzw Buchstaben ausgegeben. Ich vermute syntaktische Fehler, da die Ausgabe einer var Variable bzw eines Strings einwandfrei ausgegeben wird.
Der Code ist unten angehängt. Außerdem habe ich ein paar Screens hinzugefügt, um mein Problem zu verdeutlichen.

Danke schon mal für Hilfe.

Code:
ENGLISH:


Hi. I'm trying to create a dynamic item menu or something like an item list.
For this I want to use var and string arrays.
My problem – If I use array variables, the panel shows me nothing.
I suspect syntactical errors because the output with a var is displayed correctly.
I included the code with some screens below.
Thx in advance.


Versuch mit STRING und var Arrays - keine Ausgabe.
Try with STRING and var Array - no resualt.

Versuch mit STRING und var - Werte werden ausgegeben.
Try with simple STRING and var - values are displayed



Ach ja. Nicht über den Font wundern. Ich arbeite mit einem Linux System.
Don't be surprised about the ingame Font. I'm working with a Linux distribution.

Code:
//////////////////////////////////////////////
///Deklaration Variablen///////////
//////////////////////////////////////////////
STRING **item_StringID[5];   
int x;
var item_ID[3];  ///Aus Testgründen erst drei Indexpositionen
item_ID[1] = 0;
item_ID[2] = 0;
item_ID[3] = 0;

//////////////////////////////////////////////
///Anzeige der Items im Menü//
//////////////////////////////////////////////
PANEL* item_ID_Pan =
{
  pos_x = 10;
  pos_y = 10;
  layer = 10;
  digits(140,50,"%s","Arial#30b",1,item_StringID[1]);  ///String an der ersten Itemposition
  digits = (310, 50, 3, "Arial#30b", 1, item_ID[1]);	///Anzahl Items der ersten Itemposition
  		
  		…............. ///Weitere Itempositionen
}

//////////////////////////////////////////////
///Auflistung des Testitems///////
//////////////////////////////////////////////
function write_Items(){

	if (Heiltrank >= 1)
	{
		item_ID[1]  = Heiltrank;   ///Menge der Items, die ID 1 zugeordnet wird         
		str_cpy(item_StringID[1],"Heiltrank"); 	//Leerer String wird überschrieben
	}
	
	
…................
	

set(item_ID_Pan,SHOW | OUTLINE); 

}


function main() {
…..
/////////////////////////////////////////////////////////////////////////////
///Allokierung des Speichers für das String Array//////
////////////////////////////////////////////////////////////////////////////
	item_StringID = sys_malloc(sizeof(STRING**) * 5);
	for( x = 0; x < 5; x++)
	{
		item_StringID[x] = sys_malloc(sizeof(STRING*) * 5);
      	item_StringID[x] = str_create("");  
   
   }
…..

Posted By: Helghast

Re: Problem mit Item-Panel.(GER&ENG) - 12/06/12 08:08

The thing that jumps out to me immediatly is, that you are setting string_ID[1]..[2]..[3], shouldnt that be string_ID[0]..[1]..[2]? the index goes from 0, not from 1 (Are you not getting any errors in GameStudio on this?).

regards,
Posted By: HellThunder

Re: Problem mit Item-Panel.(GER&ENG) - 12/06/12 08:34

Ouch - you are right. It's a mistake, but not the reason of my problem.
Actually, I think it's not really important if I write something on index position 0 or not.

My panel expects a value of "item_StringID[1]"
The "write_Items" function also changes the variable of item_StringID[1].

But I've also tried to write on item_StringID[0]. No changes. =/

Compiling runs without any problems. There are no errors, when i call the item Menu.
I think there must be another syntactic error inside the script.
Posted By: Ascalon

Re: Problem mit Item-Panel.(GER&ENG) - 12/06/12 08:38

Ich glaube das Problem ist, dass in einem Panel keine Arrays ausgegeben werden können. Du müsstest mit pan_setdigits dann den aktuellen Arraywert an das Panel übermittelen, denke ich
Posted By: HellThunder

Re: Problem mit Item-Panel.(GER&ENG) - 12/06/12 09:44

Okay - problem was the wrong output format inside the Panel definition.
Panel wanted to get a float.
Code:
digits = (310, 50, "%02.0f", "Arial#30b", 1, item_ID[1]);



But my String still has the value NULL.


Okay - Problem war das falsche Ausgabeformat innerhalb der Paneldeklaration.
Panel wollte einen float haben.
Code:
digits = (310, 50, "%02.0f", "Arial#30b", 1, item_ID[1]);



Aber mein String hat trotzdem noch den Wert NULL.

Posted By: Pappenheimer

Re: Problem mit Item-Panel.(GER&ENG) - 12/07/12 20:43

Ich weiß nicht, ob ein Array mit Strings geht, aber Text ist im Grunde ein String-Array.
http://www.conitec.net/beta/atexte-intro.htm
http://www.conitec.net/beta/atext-string.htm
Posted By: HellThunder

Re: Problem mit Item-Panel.(GER&ENG) - 12/08/12 10:38

Pappenheimers Vorschlag hat die Lösung des Problems gebracht.
Die Art der Initialisierung des String Arrays war der Schlüssel.

Pappenheimers suggestion was the solution of my problem.
The way of initializing the String Array was the key.

Code:
TEXT* item_Text =
{
  pos_x = 120;
  pos_y = 20;
  font = "Arial#30b";
  string (id01, id02, id03, id04, id05, id06, id07, id08, id09, id10, id11, id12); // Array von 12 String pointers 
  flags = SHOW | OUTLINE | SHADOW;
  layer = 14;
}

function write_Items(){

if (Heiltrank >= 1)
	{		
	item_ID[1]  = Heiltrank;          
str_cpy((item_Text.pstring[1],"Heiltrank");		  
	}





Ist zwar noch nicht dynamisch - dank des Arrays stehen mir jetzt jedoch alle Wege offen.
Danke für die Hilfe aller!
regards-


After all it's still not dynamic - but because of the Array, the solution isn't far away.
Thanks for the help to all.
Grüße-
© 2024 lite-C Forums