Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Federikazzo on Wed 21/12/2005 00:27:59

Title: converting "old" code to 2.71...
Post by: Federikazzo on Wed 21/12/2005 00:27:59
i'm using the mi2 template for v2.70 and, after some tweaking, it works on v2.71.
now i'm trying to use ONLY object based scripting, and i'm stuck at this point:

function UsedInvMode(int mode, int item){
// It's used for checking if the template inventory mode passed as parameter 'mode'
// was used with the inventory item passed as parameter 'item'.
  return (UsedMode(mode) && Tmode[mode].AGSmode==4 && character[EGO].activeinv==item);

it should become
return blablablablablabla && character[EGO].ActiveInventory == item.

well... "item" is an int, and character[].ActiveInventory's type is *InventoryItem.
how can i let it work? any ideas?? ??? (sorry for my bad english, but i'm veeeeeery tired)

maybe i need to rewrite the whole template?  :o :o
let me know...
Title: Re: converting "old" code to 2.71...
Post by: Rui 'Trovatore' Pires on Wed 21/12/2005 00:31:47
You could try adding a .ID somewhere, maybe like this?

return blablablablablabla && character[EGO].ActiveInventory.ID == item

I'm not sure about this, mind - someone else who is coming along might be a lot more help - but it can't hurt to try.
Title: Re: converting "old" code to 2.71...
Post by: monkey0506 on Wed 21/12/2005 02:38:25
Yes, the ID member will give you the integer value of an InventoryItem.  Alternatively, he could replace 'item' with 'inventory[item]'.  They would both achieve the same effect.
Title: Re: converting "old" code to 2.71...
Post by: Elliott Hird on Wed 21/12/2005 10:23:43
Or rewrite it to use the iThing values properly.
Title: Re: converting "old" code to 2.71...
Post by: Rui 'Trovatore' Pires on Wed 21/12/2005 10:35:25
But if he does that, he might as well rewrite the whole template. Which seems to be undesirable, from his emoticons, and I can't say I blame him.
Title: Re: converting "old" code to 2.71...
Post by: Federikazzo on Wed 21/12/2005 10:44:32
thanks to everyone! :D

Quote from: Elliott Hird on Wed 21/12/2005 10:23:43
Or rewrite it to use the iThing values properly.

errr.... what do youexactly mean? any examples?  ::)
Title: Re: converting "old" code to 2.71...
Post by: Elliott Hird on Wed 21/12/2005 11:22:15
well it's iScriptName. There's different functions to get them instead of an int, poke around the manual a bit if you desire.
Title: Re: converting "old" code to 2.71...
Post by: Rui 'Trovatore' Pires on Wed 21/12/2005 11:32:01
He's talking about making the function return an *InventoryItem instead of an int. But I advise against it - who knows what sort of repercussions that might have, and how much code you may have to end up rewriting.
Title: Re: converting "old" code to 2.71...
Post by: Gilbert on Wed 21/12/2005 11:44:26
For generic purpose, returning the ID of an Object is enough already.
Title: Re: converting "old" code to 2.71...
Post by: Ashen on Wed 21/12/2005 11:57:39
Also for generic purposes, would it not be better to use player.ActiveInventory? (Obviously, if Federikazzo only has EGO as the player character, character[EGO], or cEgo will work).

I think Elliott meant change the function to something like:

function UsedInvMode(int mode, InventoryItem *UsedItem){
// It's used for checking if the template inventory mode passed as parameter 'mode'
// was used with the inventory item passed as parameter 'UsedItem'.
  return (UsedMode(mode) && Tmode[mode].AGSmode==4 && player.ActiveInventory == UsedItem);
}


If you were planning on rewritting the whole template for release, that would probably be the better way to go (along with using pointers for characters, GUIs, objects, etc instead of ints).
Since it looks like you're just trying to get it to work for you, the ID property is fine, or player.ActiveInventory == inventory[item].
Title: Re: converting "old" code to 2.71...
Post by: monkey0506 on Wed 21/12/2005 14:13:36
And just for the record, it's a InventoryItem*, not *InventoryItem.  The asterik can be attached to the variable type or the variable name, but it should never proceed the type.
Title: Re: converting "old" code to 2.71...
Post by: Federikazzo on Wed 21/12/2005 15:52:54
thanks to you all!

i think i'm going to rewrite the whole template btw, cos it doesn't work properly at the moment.
ok, maybe i've made some mistakes with the new code, but i don't mind.
i'll try to make a working template so that anyone can use it with the newer versions of ags.

...i just hope i can make it!  :o