1 registered members (AndrewAMD),
1,251
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
calculate stringpointer
#410697
11/07/12 11:56
11/07/12 11:56
|
Joined: Oct 2012
Posts: 6
Kaaron
OP
Newbie
|
OP
Newbie
Joined: Oct 2012
Posts: 6
|
A8.10.1 Lite-C Commercial Hi Folks, some time now i try to create a textsystem as matchable as possible. For this i would like to standardise all stringnames by numbers and calculate the right string by mean of variables in a 2nd string. The CONTEND of this 2nd string should be usable as a pointer to the string to chose. Despite i searched for days, i unfortunately couldn’t figure out how to use a string as a pointer. "engine_getobj" seems promising first, but it didn’t do what i want (perhaps I overlooked something?). Does anyone know how to make this work? Ps: I know about "text.pstring" but the functionality isn’t quite what i need. ________________________________________________________________ Hallo Leute, ich versuche mich jetzt schon länger an einem möglichst anpassungsfähigen Textsystem. Hierzu würde ich gerne alle Stringnamen per Nummern standardisieren und den zu wählenden String mit Hilfe von Variablen in einem 2. String zu berechnen. Der INHALT dieses 2. String soll also als Pointer des zu wählenden Strings fungieren. Leider konnte ich auch nach tagelangem Durchsuchen des Internets keine Lösung finden einen String als Pointer zu verwenden. Einige Hoffnung hatte ich in "engine_getobj" gesetzt, hatte aber leider auch keinen Erfolg (oder ich habe da etwas übersehen?). Kennt jemand eine Möglichkeit? Ps: Mir ist klar, dass es "text.pstring" gibt, doch die Funktionsweise ist nicht ganz das, was ich möchte. ________________________________________________________________ Example:
var got_key = 0; // did the player find the key?
STRING* dia_str = ""; // this String will be showen while talking
/////// First entity ///////
// First dialog (while player haven't find the key)
STRING* dia_1_1_1 = "Hello little man.";
STRING* dia_1_1_2 = "I lost my key.";
STRING* dia_1_1_3 = "Would be nice if you find him.";
// Second dialog (the player had found the key)
STRING* dia_1_2_1 = "Wow, you have found the key.";
STRING* dia_1_2_2 = "Thanks a lot.";
/////// Second entity ///////
// First dialog
STRING* dia_str_2_1_1 = "What do you want???";
STRING* dia_str_2_1_2 = "Don't bend my ears!";
//(...)
function talk(C, D) // C = ID for NPC, D = Dialoggroup
{
var S = 1; // S = current string to show
STRING* my_string = ""; // this string should contain the pointer of the string
str_cpy(my_string, "dia_"); // Prefix
str_cat_num(my_string, "%.0f_", C); // add the NPC-ID and a _
str_cat_num(my_string, "%.0f_", D); // add the ID for the dialoggroup and a _
str_cat_num(my_string, "%.0f", S); // add the ID for the current string
/*!!!*/ while(str_to_ptr(my_string) != NULL) // ptr_for_str don't exist, this is what i'm seraching for!
{
str_cpy(dia_str, str_to_ptr(my_string)); // by the first time my_string contains dia_str_1_1_1
wait(-1); // display the text at minimum 1 second...
while(key_space != 1){wait(1);} // ...then wait till space is pressed
S += 1; // raise for next string
// this is same like before whith new value of S
// existence will be checked at the top of the loop
str_cpy(my_string, "dia_");
str_cat_num(my_string, "%.0f_", C);
str_cat_num(my_string, "%.0f_", D);
str_cat_num(my_string, "%.0f", S);
}
}
action anyone()
{
// (...)
if(got_key == 0) {talk(1,1);} // first dialog
else {talk(1,2);} // second dialog
// (...)
}
Last edited by Kaaron; 11/07/12 13:15.
Gamestudio Commercial A8.45 - Lite-C
|
|
|
Re: calculate stringpointer
[Re: Kaaron]
#410700
11/07/12 12:44
11/07/12 12:44
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
A8.10.1? Welche Edition denn?
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: calculate stringpointer
[Re: Kaaron]
#410707
11/07/12 13:24
11/07/12 13:24
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Dann update doch mal auf A8.4. Was du suchst ist wahrscheinlich http://www.conitec.net/beta/engine_getvar.htm.Das solltest Du nicht in einer Funktion tun. Das ist ein Character Array, kein String pointer. Zudem solltest Du Funktionsparameter immer mit Typ deklarieren. Ich bin überrascht, dass der Compiler das überhaupt so schluckt. Zu Deinem Ansatz: Das kann man so machen. Effizient und sinnvoll ist das aber nicht. Im einfachsten Fall kannst Du einfach ein zwei dimensionales Array für Deine Strings verwenden. Wenn die IDs nicht fortlaufend sind kannst Du auch Hashmaps von Hashmaps verwenden.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: calculate stringpointer
[Re: Uhrwerk]
#410712
11/07/12 14:39
11/07/12 14:39
|
Joined: Feb 2009
Posts: 3,207 Germany, Magdeburg
Rei_Ayanami
Expert
|
Expert
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
|
Zudem solltest Du Funktionsparameter immer mit Typ deklarieren. Ich bin überrascht, dass der Compiler das überhaupt so schluckt. Wenn es nicht deklariert wird, wird var angenommen.
|
|
|
Re: calculate stringpointer
[Re: Rei_Ayanami]
#410761
11/08/12 13:02
11/08/12 13:02
|
Joined: Oct 2012
Posts: 6
Kaaron
OP
Newbie
|
OP
Newbie
Joined: Oct 2012
Posts: 6
|
Dann update doch mal auf A8.4 Erledigt. STRING* my_string = ""; Das solltest Du nicht in einer Funktion tun. Warum nicht? Meine das schon häufiger in Conitec-scripten gesehen zu haben, konnte spontan allerdings auch kein Beispiel finden. Müsste doch (genau so wie bei den Variablen) als lokaler String gehandhabt werden, oder nicht? (...) kannst Du auch (...) Hashmaps verwenden Von Hashmaps höre ich zum ersten mal. Habe mich ein wenig schlau gemacht, eine entsprechende dll gefunden, ne Weile rumprobiert und siehe da: es funktioniert Vielen Dank @ Uhrwerk Wer Hashmaps in lite-C verwenden will sollte mal bei Hashmap_dll oder Hashmaps_C rein schauen. Hier der angepasste Code meiner Testdatei: (!) GSHashmap.dll und GSHashmap.h aus dem ersten Link werden benötigt. (!)
///////////////////////////////////////////////////////////////////////
// requires GSHashmap.dll and GSHashmap.h from:
// http://www.opserver.de/wiki/index.php?title=Plugins#GSHashmap_DLL
///////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include "GSHashmap.h"
STRING* dia_str = ""; // this String will be showen while talking
STRING* my_str = ""; // this string contains the pointer of the string
STRING* info_str = "press T";
var got_key = 0; // did the player find the key?
TEXT* show_dialog =
{
pos_x = 10; pos_y = 10;
string = dia_str;
flags = SHOW;
}
TEXT* show_info =
{
pos_x = 20; pos_y = 50;
string = info_str;
flags = SHOW;
}
function anyone();
function create_dialogs();
function exit_prog(){sys_exit("");}
void main()
{
video_screen = 2;
on_q = exit_prog;
create_dialogs();
anyone();
}
function create_dialogs() // called in main-function
{
/////// First entity ///////
// First dialog (while player haven't find the key)
addToGSHashmap(_chr("dia_1_1_1"), _str("Hello little man."));
addToGSHashmap(_chr("dia_1_1_2"), _str("I lost my key."));
addToGSHashmap(_chr("dia_1_1_3"), _str("Would be nice if you find him."));
// Second dialog (the player had found the key)
addToGSHashmap(_chr("dia_1_2_1"), _str("Wow, you have found the key"));
addToGSHashmap(_chr("dia_1_2_2"), _str("Thanks a lot"));
/////// Second entity ///////
// First dialog
addToGSHashmap(_chr("dia_2_1_1"), _str("What do you want???"));
addToGSHashmap(_chr("dia_2_1_2"), _str("Don't bend my ears!"));
//(...)
}
function talk(var C, D) // C = ID for NPC, D = Dialoggroup
{
var S = 1; // S = current string to show
str_cpy(my_str, "dia_"); // Prefix
str_cat_num(my_str, "%.0f_", C); // add the NPC-ID and a _
str_cat_num(my_str, "%.0f_", D); // add the ID for the dialoggroup and a _
str_cat_num(my_str, "%.0f", S); // add the ID for the current string
while(isInGSHashmap(_chr(my_str)) == 1) // check if the entry with the given key exists in the hashmap
{
str_cpy(dia_str, (STRING*)getFromGSHashmap(_chr(my_str))); // by the first time my_str contains dia_str_1_1_1
wait(-0.5); // display the text at minimum 0.5 seconds...
while(key_space != 1){wait(1);} // ...then wait till space is pressed
S += 1; // raise for next string
// this is same like before whith new value of S
// existence will be checked at the top of the loop
str_cpy(my_str, "dia_");
str_cat_num(my_str, "%.0f_", C);
str_cat_num(my_str, "%.0f_", D);
str_cat_num(my_str, "%.0f", S);
}
str_cpy(dia_str, "");
str_cpy(info_str, "press T");
}
function anyone()
{
while(1)
{
while (!key_t){wait(1);}
while (key_t){wait(1);}
str_cpy(info_str, "press space");
if(got_key == 0) {talk(1,1); got_key = 1;} // first dialog
else {talk(1,2); got_key = 0;} // second dialog
}
}
Gamestudio Commercial A8.45 - Lite-C
|
|
|
Re: calculate stringpointer
[Re: Kaaron]
#410762
11/08/12 13:07
11/08/12 13:07
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Lite Foundation hat übrigens auch hashmap implementationen, direkt in Lite-C und Open Source. Ich dachte ich plug den alten scheiß mal wieder (auf den Datums und String kram bin ich übrigens immer noch stolz) Warum nicht? Meine das schon häufiger in Conitec-scripten gesehen zu haben, konnte spontan allerdings auch kein Beispiel finden. Müsste doch (genau so wie bei den Variablen) als lokaler String gehandhabt werden, oder nicht? Nein, in dem Scope einer Funktion ist "", genau wie in normalen C, ein pointer zu einem leeren character array.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
|