|
-
Verwendung von Hlp_GetInstanceId?
Kann mir bitte jemand erklären, was Hlp_GetInstanceId tatsächlich macht (je nach Argument?) und wann man es verwenden sollte?
Ein Problem, bei dem mir mein Mangel an Verständnis aufgefallen ist:
In LoA verwenden wir an diversen Stellen so etwas wie
Code:
if (Hlp_GetInstanceID (ItMw_Smith_2H_01) == ...)
ItMw_Smith_2H_01 ist hier die Instanz (?)
Code:
instance ItMw_Smith_2H_01(C_Item)
{
name = "Einfacher Zweihänder";
mainflag = ITEM_KAT_NF;
flags = ITEM_2HD_SWD;
material = MAT_METAL;
value = Value_Schwert1;
damageTotal = 60;
damagetype = DAM_EDGE;
range = Range_Sld2hSchwert;
on_equip = Equip_2H_05;
on_unequip = UnEquip_2H_05;
cond_atr[2] = ATR_STRENGTH;
cond_value[2] = 50;
visual = "ItMw_035_2h_sld_sword_01.3DS";
description = name;
text[2] = NAME_Damage;
count[2] = damageTotal;
text[3] = NAME_Str_needed;
count[3] = cond_value[2];
text[4] = NAME_ADDON_BONUS_2H;
count[4] = Waffenbonus_05;
text[5] = NAME_Value;
count[5] = value;
};
Ich gehe nun wie folgt vor:
1) starte ein neues Spiel
2) rufe auf Hlp_GetInstanceId(ItMw_Smith_2H_01) -> Rückgabewert eine mehrstellige positive Zahl
3) rufe auf CreateInvItems(hero,ItMw_Smith_2H_01,1);
4) rufe auf Hlp_GetInstanceId(ItMw_Smith_2H_01) -> Rückgabewert dieselbe Zahl
5) rufe auf CreateInvItems(hero,ItMw_Smith_2H_01,1);
6) rufe auf Hlp_GetInstanceId(ItMw_Smith_2H_01) -> Rückgabewert -1
Was ist hier passiert?
Wenn ich statt des Aufrufs von CreateInvItems das Item (zweimal) im Marvin Mode einfüge und dann einsammel, kommt am Ende nicht -1 heraus, sondern immernoch die mehrstellige positive Zahl, die ich erwarten würde.
Ich nehme an, dass wir, als wir bei LoA da einigen Code geschrieben haben, nicht ganz verstanden haben, was Hlp_GetInstanceId eigentlich macht, und es mehr oder weniger auf alles angewandt, wenn wir Vergleichen wollten, ob ein Item von einer bestimmten instanz kommt, ob ein Npc ein bestimmter Npc ist,...
Sollte man jemals
Code:
Hlp_GetInstanceId(ItMw_Smith_2H_01)
schreiben oder ist das praktisch eigentlich immer Quatsch aber meist unproblematisch?
Sollten Vergleiche immer so aussehen:
Code:
if Hlp_GetInstanceId(itm) == ItMw_Smith_2H_01
bzw. für Npc
Code:
if Hlp_GetInstanceId(slf) == SLD_6118_Marand
? (wo anderswo definiert ist instance SLD_6118_Marand (C_NPC) { ...};)
Gibt es da irgendwelche Abhängigkeiten davon, ob man einen Spielstand verwendet, der mit einer älteren Version der Skripte gestartet wurde (weil sich Symbol-Indices verschieben?)?
Ich meine, dass das hier schon mal jemand jemand anderem im Forum erklärt hat, konnte es jetzt aber über die Forensuch nicht mehr finden. Ggf. würde mir also vielleicht sogar schon ein Link reichen, wenn sich da schon mal jemand Mühe gegeben hatte mit einer Erklärung
-
Zitat von Milky-Way
Sollten Vergleiche immer so aussehen:
Code:
if Hlp_GetInstanceId(itm) == ItMw_Smith_2H_01
bzw. für Npc
Code:
if Hlp_GetInstanceId(slf) == SLD_6118_Marand
?
Meiner Meinung nach, ja.
https://forum.worldofplayers.de/foru..._getInstanceID
-
-
Zitat von Milky-Way
Danke, dann schaue ich mir mal unsere 3043 Stellen an, an denen wir die Funktion benutzen...
Falls noch jemand eine Idee hat, wieso in der Konstellation mit CreateInvItems das Spiel die Hlp_GetInstanceId(ItMw_Smith_2H_01) nicht mehr hinbekommt, bin ich prinzipiell noch interessiert, auch wenn ich letztlich bereits eine Lösung für mein Problem habe
ItMw_Smith_2H_01 in integer context is index of corresponding parser symbol. This value can be changed on script recompilation, and not during the game.
ItMw_Smith_2H_01 in instance context is pointer to the last created item of that type. If such an item is never created (ex., can no be found in the world) or the last created item gets destroyed (ex., uniting items in inventory) then the pointer is null.
You should never call Hlp_GetInstanceID(ItMw_Smith_2H_01) - it is meaningless. Just use ItMw_Smith_2H_01 directly as integer.
You should pass an instance variable to Hlp_GetInstanceID. Ex.:
Code:
// asumed that None_100_Xardas and PC_Hero are in the world
func void Test()
{
var C_NPC npc;
if (Hlp_Random(2) == 0)
{
npc = Hlp_GetNpc(None_100_Xardas);
}
else
{
npc = Hlp_GetNpc(PC_Hero);
};
if (Hlp_GetInstanceID(npc) == None_100_Xardas)
{
Print("Xardas has been choosen");
}
else
{
Print("Hero has been choosen");
};
};
Geändert von TopLayer (28.03.2021 um 05:54 Uhr)
-
Zitat von Milky-Way
Kann mir bitte jemand erklären, was Hlp_GetInstanceId tatsächlich macht (je nach Argument?) und wann man es verwenden sollte?
Hi Milky-Way,
Description:
int Hlp_GetInstanceID (c_npc npc); // get the npc ID number from the link to the npc class.
int Hlp_GetInstanceID (c_item item); // get the item ID number from the link to the item class.
Example:
Code:
// =====================================
// Is the NPC a Hero
// -------------------------------------
// Arguments: slf - checked NPC
// -------------------------------------
// Returned value: TRUE - yes, FALSE - no.
// =====================================
func int C_NpcIsHero (var c_npc slf)
{
var c_npc her;
// get the link to the Hero
her = Hlp_GetNpc (PC_Hero);
// if NPC and Hero IDs are equal
if (Hlp_GetInstanceID (slf) == Hlp_GetInstanceID (her))
{
return TRUE;
};
return FALSE;
};
For items, everything is done in the same way.
MfG MaGoth,
-
Thank you all for the explanations!
Zitat von TopLayer
ItMw_Smith_2H_01 in integer context is index of corresponding parser symbol. This value can be changed on script recompilation, and not during the game.
ItMw_Smith_2H_01 in instance context is pointer to the last created item of that type. If such an item is never created (ex., can no be found in the world) or the last created item gets destroyed (ex., uniting items in inventory) then the pointer is null.
You should never call Hlp_GetInstanceID(ItMw_Smith_2H_01) - it is meaningless. Just use ItMw_Smith_2H_01 directly as integer.
You should pass an instance variable to Hlp_GetInstanceID. Ex.:
Code:
// asumed that None_100_Xardas and PC_Hero are in the world
func void Test()
{
var C_NPC npc;
if (Hlp_Random(2) == 0)
{
npc = Hlp_GetNpc(None_100_Xardas);
}
else
{
npc = Hlp_GetNpc(PC_Hero);
};
if (Hlp_GetInstanceID(npc) == None_100_Xardas)
{
Print("Xardas has been choosen");
}
else
{
Print("Hero has been choosen");
};
};
Great, that makes sense then for why I got -1 when the next item stacks. Not quite sure why it doesn't happen when I collect the second item from the world though (insert two in marvin mode, then collect both) - how can the pointer to the last item of this type survive?
-
Zitat von Milky-Way
insert two in marvin mode, then collect both
Collect in which order? The very first collected item shouldn't be destroyed - it is in your inventory as vob until you save the game or oCNpcInventory :: PackAllItems is explicitly called or ... might be some other cases: it is about game internals you shouldn't rely on.
Object is destroyed not when it gets removed from world or from somethere but when its refCtr gets reduced to zero (methods zCObject :: AddRef and zCObject :: Release are used to control this value).
-
Zitat von TopLayer
Collect in which order? The very first collected item shouldn't be destroyed - it is in your inventory as vob until you save the game or oCNpcInventory :: PackAllItems is explicitly called or ... might be some other cases: it is about game internals you shouldn't rely on.
Object is destroyed not when it gets removed from world or from somethere but when its refCtr gets reduced to zero (methods zCObject :: AddRef and zCObject :: Release are used to control this value).
Thanks! I had always just inserted the two items on the same spot, so couldn't tell the difference. If I spawn them in different spots so I can tell them apart:
- picking up the item inserted first, then the item inserted second: -1
- picking up the item inserted second, then the item inserted first: 26...
So the first collected item survives the stacking, just as you predicted.
Thanks for the explanations (and fun experiment)!
Berechtigungen
- Neue Themen erstellen: Nein
- Themen beantworten: Nein
- Anhänge hochladen: Nein
- Beiträge bearbeiten: Nein
|
|