converting "old" code to 2.71...

Started by Federikazzo, Wed 21/12/2005 00:27:59

Previous topic - Next topic

Federikazzo

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...
Signatures are displayed at the bottom of each post or personal message. BBC code and smileys may be used in your signature.

Rui 'Trovatore' Pires

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.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

monkey0506

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.

Elliott Hird

Or rewrite it to use the iThing values properly.

Rui 'Trovatore' Pires

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.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Federikazzo

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?  ::)
Signatures are displayed at the bottom of each post or personal message. BBC code and smileys may be used in your signature.

Elliott Hird

well it's iScriptName. There's different functions to get them instead of an int, poke around the manual a bit if you desire.

Rui 'Trovatore' Pires

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.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Gilbert

For generic purpose, returning the ID of an Object is enough already.

Ashen

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:
Code: ags

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].
I know what you're thinking ... Don't think that.

monkey0506

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.

Federikazzo

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
Signatures are displayed at the bottom of each post or personal message. BBC code and smileys may be used in your signature.

SMF spam blocked by CleanTalk