Author Topic: If statement involving datablocks  (Read 637 times)

So, scripting my CityRPG, i've run into a problem, and figured the best way to fix it would be using an if statement.

like,

 if the datablock is IronOre, then 'if' is true, so do that

 if the datablock is SilverOre, then 'if else' is true, so do that

 if the datablock is PlatinumOre, then 'else' is true, so do that

how exactly would I go about doing this? any help greatly appreciated. im guessing itd be something around the lines of if %datablock.ironore 'so here'

Oh my lord.

I told you not to do it this way as it prevents you from adding an ore without changing the script around.

Yola, I know. I planned on it, sheesh, don't worry.

Yola, I know. I planned on it, sheesh, don't worry.
I told you that, last night.
Then boom you posted this today, so obviously you didn't plan on it.

Define a property in your datablock like oreType, then set it equal to whatever names you want to use.

An example of an if/else chain that you could use looks like this:
Code: [Select]
//Datablock
datablock whatever
{
    properties = asfasf;
    oreType = "exampleOre";
}

//Using it
%oreType = %yourObject.getDataBlock().oreType
if(%oreType $= "IRON")
    //treat this object as iron
else if(%oreType $= "GOLD")
    //treat this object as gold
else if(%oreType $= "UNOBTANIUM")
    //go forget yourself
else if(%oreType $= "PLATINUM")
    //treat this object as platinum

However, if you're using this the way I think you're using it, you might as well just define all of the ore's health and value and the exp within the datablock as well. You can dynamically reference them like this:
Code: [Select]
function onOreMined(%ore,%player)
{
    %data = %ore.getDataBlock();
    %player.addMoney(%data.value);
    %player.addExp(%data.exp);
    //etc.
}

Thanks, Trey, that's a great way of doing it, didn't think of that :D

Thanks, Trey, that's a great way of doing it, didn't think of that :D
What the forget?
That's literally EXACTLY how I showed you and told you to do it.

What the forget?
That's literally EXACTLY how I showed you and told you to do it.
wow.

maybe he just wasn't to jazzed to hear it from you or something.

wow.

maybe he just wasn't to jazzed to hear it from you or something.
hue

Anyway yeah, he always does that.

No, you just had a really stuffty way of explaining it. You wanted me to change one ofyour number based preferences of the datablock to iron or whatever.

Can you two quit arguing in every thread? You guys are acting like teen school girls.

No, you just had a really stuffty way of explaining it. You wanted me to change one ofyour number based preferences of the datablock to iron or whatever.

The forget?
I told you change "resourceYield" property already in the datablock to "Iron" or whatever, then change the code to accommodate it.

Can you two quit arguing in every thread? You guys are acting like teen school girls.

He never, ever listens to me.