• 0
Sign in to follow this  
caspa

Explain getd because i don't understand :(

Question

Posted (edited)

can somebody explain to me why there is a 0 in this part   delitem2 [email protected],1,1,getd("[email protected]_inf"[email protected]+"[4]"),0, and why there is a successive same getd ,getd("[email protected]_inf"[email protected]+"[0]"),getd("[email protected]_inf"[email protected]+"[1]"),getd("[email protected]_inf"[email protected]+"[2]"),getd("[email protected]_inf"[email protected]+"[3]"); after that?
 

                successrefitem [email protected];
                set [email protected], [email protected] - 1;
                if([email protected] <= 0) close;
                set [email protected], 0;
                while ( getequiprefinerycnt([email protected]) >= [email protected] ) {
                    for (set [email protected], 0; [email protected] < 4; set [email protected], [email protected] + 1)
                        if (getequipcardid([email protected],[email protected]) != 0)
                            setd "[email protected]_inf"[email protected]+"[[email protected]]", getequipcardid([email protected],[email protected]);
                    setd "[email protected]_inf"[email protected]+"[4]", getequiprefinerycnt([email protected]);
                    unequip [email protected];
   delitem2 [email protected],1,1,getd("[email protected]_inf"[email protected]+"[4]"),0,getd("[email protected]_inf"[email protected]+"[0]"),getd("[email protected]_inf"[email protected]+"[1]"),getd("[email protected]_inf"[email protected]+"[2]"),getd("[email protected]_inf"[email protected]+"[3]");
                    equip [email protected];
                    set [email protected], [email protected] + 1;
                }
                if ([email protected]) {
                    for (set [email protected], 0; [email protected] < [email protected]; set [email protected], [email protected] + 1) {
   getitem2 [email protected],1,1,getd("[email protected]_inf"[email protected]+"[4]"),0,getd("[email protected]_inf"[email protected]+"[0]"),getd("[email protected]_inf"[email protected]+"[1]"),getd("[email protected]_inf"[email protected]+"[2]"),getd("[email protected]_inf"[email protected]+"[3]");
                    }
                }
            }
Edited by caspa

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0
[email protected]something = 10;
[email protected]string$ = "thing";

mes "" + getd("[email protected]" + [email protected]string$);
mes "" + [email protected]something;


//[email protected]some + ([email protected]string$ = "thing";)
//[email protected]some + thing
//[email protected]something
//getd("[email protected]" + [email protected]string$) == [email protected]something

-----------------------------------------------------
[email protected]var0 = 0;
[email protected]var1 = 5;
[email protected]var2 = 10;
[email protected]var3 = 15;

for([email protected]i=0;[email protected]i<4;[email protected]i++)
	mes "" + getd("[email protected]" + [email protected]i);

//getd("[email protected]" + 0) == [email protected]var0
//getd("[email protected]" + 1) == [email protected]var1
//getd("[email protected]" + 2) == [email protected]var2
//getd("[email protected]" + 3) == [email protected]var3

 

it's easy you just need to test it , than you understand it

 

  • Upvote 1

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

Also, for instructive purposes:

From rA\doc\script_commands.txt:

*delitem2 <item id>,<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>};

This command will remove a specified amount of items from the invoking/target character.
See 'getitem2' for an explanation of the expanded parameters.

On the script excerpt you provided, the delitem2 argument you request an explanation for (the number zero) occupies the 5th position, that of the <attribute> parameter.
The delitem2 command explanation forwards us to getitem2 for explanation on these parameters.

From rA\doc\script_commands.txt:

identify    - Whether you want the item to be identified (1) or not (0).
refine      - For how many pluses will it be refined.
              It will not let you refine an item higher than the max refine.
attribute   - Whether the item is broken (1) or not (0).
card1,2,3,4 - If you want a card compound to it, place the card ID number into
              the specific card slot.

Here is your explanation for that parameter.

Now, regarding the use of getd, let's first take a look at this command at rA\doc\script_commands.txt:

*getd("<variable name>")

Returns a reference to a variable, the name can be constructed dynamically.
Refer to 'setd' for usage.

In order for you to properly understand getd, you need to first understand how to use basic variables and arrays (skip the spoiler if you do).

Spoiler

 

Setting a variable's value:

set <variable_name>, <variable_value>; // For single-value variables
setarray <array_name>[0], {<value_0>, <value_1>, <value_2>, ...};

Examples:

set [email protected]_id, 19015; // Sets the value 19015 to [email protected]_id
setarray [email protected]_list[0], 501, 502, 503, 504, 505; // Sets the values [501, 502, 503, 504, 504] to [email protected]_list
set [email protected]_name$, "Valkyrie's Magic Bow";
setarray [email protected]_items$[0], "Where should I go?", "About the Basic Interface", "Who the crap are you?!";

To read a variable's value, you simply use it as if it were a value in your script:

set [email protected]_name$, strcharinfo(0); // Here the variable's value is SET.

mes "[ A Really-Human NPC ]";
mes "Yo, what's up, " + [email protected]_name$ + "?!"; // Here the variable's value is READ.

 

Assuming that you already understand how basic variables and arrays really work, this is the magic of getd: It allows you to choose which variables you want to set/read WHILE the script is executing.

When you use basic variables and arrays, you're saying exactly where to place or to find the data you're looking for (e.g.: "I want to set the character's name to the variable named [email protected]_name$." or "I want to set [501, 502, 503, 504, 505] to the array named [email protected]_list."). This is fixed: after the server's loaded the script, you can't open an input and ask the player: "Hey, tell me the name of the variable you want me to store this amount of Jellopies in:".

With getd you actually can do that (even though you shouldn't! ). That certainly is not the only use for getd, nor the most common: it is often used to make scripting simpler, and although I will refrain from attempting to document all occasions when its use would be beneficial, I'll provide you with an example which I find both instructive and simple enough.

Let's say you have a Treasure Chest NPC, and whenever the player interacts with it, you want to give him a set of items. You have 5 different set of items, represented by 5 different arrays, and you want your script to randomly choose which set of items to reward the lucky player. So, you have something like this:

setarray [email protected][0], 501, 502, 503;
setarray [email protected][0], 620, 630, 640, 650;
setarray [email protected][0], 711, 722, 733, 744, 755;
setarray [email protected][0], 888, 999, 1010, 1111, 1212, 1313;
setarray [email protected][0], 1010, 1111, 1212, 1313, 1414, 1515, 1616;

How do you  randomly select one of these arrays to reward the player with its items?

Sure, you're definitely going to use the rand() function to generate a number that is in the range of [1, 5]. vvvv But, please, don't do this. vvvv

Spoiler
set .@picked_reward, rand(1,5);

switch (.@picked_reward) {
case 1:
    for (.@i = 0; .@i < getarraysize(.@rewards1); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
    break;
case 2:
    for (.@i = 0; .@i < getarraysize(.@rewards2); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
    break;
case 3:
    for (.@i = 0; .@i < getarraysize(.@rewards3); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
    break;
case 4:
    for (.@i = 0; .@i < getarraysize(.@rewards4); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
    break;
case 5:
    for (.@i = 0; .@i < getarraysize(.@rewards5); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
    break;
}

Or

set .@picked_reward, rand(1,5);

if (.@picked_reward == 1) {
    for (.@i = 0; .@i < getarraysize(.@rewards1); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
} else if (.@picked_reward == 2) {
    for (.@i = 0; .@i < getarraysize(.@rewards2); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
} else if (.@picked_reward == 3) {
    for (.@i = 0; .@i < getarraysize(.@rewards3); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
} else if (.@picked_reward == 4) {
    for (.@i = 0; .@i < getarraysize(.@rewards4); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
} else if (.@picked_reward == 5) {
    for (.@i = 0; .@i < getarraysize(.@rewards5); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
}

 

With getd, you can simply do the following:

set .@picked_reward, rand(1,5); // The number of the picked reward

// Rewards array name
set .@chosen_rewards, "[email protected]" + .@picked_reward;

// How many of each item inside the rewards list to give the player
set .@amount_per_item, 1;

for (.@i = 0; .@i < getarraysize(getd(.@chosen_rewards)); .@i++) {
  giveitem getd(.@chosen_rewards + "[" + .@i + "]"), .@amount_per_item;
}

Line 1 picks a random number from 1 to 5 to identify which array of items it wants to give to the player.

Line 4 effectively adds the string "[email protected]" to the picked number, so "[email protected]" + 4, for example, yields "[email protected]" and stores that in [email protected]_rewards.

Line 7 sets how many of each item in the rewards list to reward the player with.

Line 9 is where getd is first used. When you use the getd() function providing a string, you're effectively dealing with the value of the variable whose name is the provided string. So, in case the picked reward was number 4, you're actually dealing with [email protected], which is an array, hence why we're measuring it's size with getarraysize().

Line 10 concatenates the array's name with it's element so that we can actually access each of the array's elements. In case the picked reward was number 4, it concatenates the string "[email protected]" and "[[email protected]]", with [email protected] being repeatedly replaced by numbers from 0 to x, where x is getarraysize([email protected]) - 1. So it goes over the array, item by item, giving the defined amount to the invoking character.

So, this is pretty much all there is to it. I hope this is as instructive as it is exhausting.

Edited by Tyrfing

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this