About Store Forum Documentation Contact



Post Reply 
Strange object creatig bug
Author Message
AndrewBGS Offline
Member

Post: #1
Strange object creatig bug
I am trying to dynamically create an object when another object is created (create an apple when a tree is created).

Apparently, the object is created; It's there, I can see the apple, it is highlighted when I hover over it as any other apple. However, if I pick it up, it looks as if its parameters were not set; It has no icon, no name, nothing;

The same apple dropped directly in the world, behaves perfectly fine with all it's parameters. So from exactly the same object, by creating it in code under the Tree constructor my parameters are not considered, but when it's created default by the engine it all works fine.

I create with the Game.World.ObjCreate() function. Am I missing something?
How can two object created from the same UID behave different?
03-16-2014 09:39 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #2
RE: Strange object creatig bug
I've done some digging, it turns out creation isn't exactly the problem;

My apple is created correctly with all parameters fine, but everything goes wrong when the player is trying to pick it up;
My bet is the line

Item *item= &SCAST(Item, *Lit); // or: Item *item=CAST(Item,Lit)

causes this problem.

But I still can't figure out why; why does this work for all other apples in the world but not for the apple created by the tree? Any thoughts..?
(This post was last modified: 03-20-2014 09:02 AM by AndrewBGS.)
03-20-2014 09:01 AM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #3
RE: Strange object creatig bug
Make sure the item is getting created at the right scope and is not getting deleted.
03-20-2014 04:36 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #4
RE: Strange object creatig bug
It is.
I've checked, the item is created correctly.
Right before picking it up, while highlighted, I can see its name, it's "apple". But after I click it to pick it up, it is destroyed and it has the default parameters of Item.
03-20-2014 06:24 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #5
RE: Strange object creatig bug
So when it's picked up, you store a reference or a pointer to it, then the original is deleted?
03-20-2014 06:32 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #6
RE: Strange object creatig bug
Pretty much; I'm using the same principle as in the Tutorial "Game Basics/Inventory", with some modifications;

Get a pointer to the object in the world, create a replicate of it in the inventory, then delete the original;
However, the name of the object is lost between these 3 lines of code:

if(Lit) DebugWin.updateTxt(S+CAST(Item , Lit).name);
if(Lit && Ms.bp(0)) if(Item *item=CAST(Item, Lit))
{ DebugWin.updateTxt(S+"picked up "+item.name);

The first and the last are just used for debugging; The first line showws me the name of the item whenever it is highlited (Lit). The last one shows me the name of the item after it was clicked;

The first one correctly says "Apple", while the 3rd says "Not created" - default Item name.

The strangest part is, this never occurs with objects created by being placed on the world map directly.

Update: I replaced the 2nd debug line with:

DebugWin.updateTxt(S+CAST(Item , Lit).name); //same as the first, reading name of Lit directly

It turns out after that line Lit is lost also, so maybe it's not the cast...? I don't have a hypothesis yet. And this is driving me nuts.
(This post was last modified: 03-20-2014 06:44 PM by AndrewBGS.)
03-20-2014 06:42 PM
Find all posts by this user Quote this message in a reply
Post Reply