Jump to content
  • 0

How can i copy npc array from another NPC?


anacondaq

Question


  • Group:  Members
  • Topic Count:  42
  • Topics Per Day:  0.01
  • Content Count:  1096
  • Reputation:   345
  • Joined:  02/26/12
  • Last Seen:  

I have few questions.

 

 

1.) Is that possible to do next thing? (or any another altenative)

NPC_A

setarray .somearray$[0],"value","value2","value3";

NPC_B

$@variable$ = getvariableofnpc(.somearray$[1],"NPC_A");

2.) Is that possible to copy array from destination array in NPC to source array? Example:

 

NPC_A

setarray .array_name[0],1,2,3,4,5,6,7,8;

NPC_B

setarray .some_array[0],2,3,6,2,351,6;

NPC_C (here i want to get NPC based arrays to 3rd NPC from above)

copyarray .thirdarray[0],.array_name[5],.some_array[3];

3.) About variables names and their "visible zone" in NPC

 

Tell me please, if i have two NPC, for example

 

NPC_A

.somevalue = 1;

NPC_B

.somevalue = 1;

Does both variable names will work with UNIQUE (NPC BOUNDED variable) or it will be only one variable for both?

I mean, Does NPC variables (it's hard to explain with my english) https://en.wikipedia.org/wiki/Scope_(programming)?

 

4.) 

 

I like to read script code from different scriptes here (AnieRuru, Euphy) (i'm somethings learning some new tricks in their scripts)

Is there any good examples of advansed scripting examples?

 

(i do not talk about wiki exaples like dyn menu, or if/else statement (var)?:this:else, i'm talking about more examples of that tricks);

 

For example mini questions about some command

 

There is no error

deletearray .@array_name$;

In documentation is

deletearray .@array_name$[ where to start ], how many to remove;

I saw that command in few scripts, does that mean it's totally remove array? Or what that is do?

 

Thank you.

Edited by Anacondaqq
Link to comment
Share on other sites

4 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  666
  • Reputation:   93
  • Joined:  04/27/12
  • Last Seen:  

"." - A NPC variable.
They exist in the NPC and disappear when the server restarts or the
NPC is reloaded. Can be accessed from inside the NPC or by calling
'getvariableofnpc'. Function objects can also have .variables which
are accessible from inside the function, however 'getvariableofnpc'
does NOT work on function objects.

*getvariableofnpc(<variable>,"<npc name>")
Returns a reference to a NPC variable (. prefix) from the target NPC.
This can only be used to get . variables.
Examples:
//This will return the value of .var, note that this can't be used, since the value isn't caught.
getvariableofnpc(.var,"TargetNPC");
//This will set the .v variable to the value of the TargetNPC's .var variable.
set .v, getvariableofnpc(.var,"TargetNPC");
//This will set the .var variable of TargetNPC to 1.
set getvariableofnpc(.var,"TargetNPC"), 1;
Note: even though function objects can have .variables,
getvariableofnpc will not work on them.

@1: Yes, it should be possible using this method.

@2: You need to use getvariableofnpc for each instance of needing to use the variable from another NPC.

@3: As Skorm mentions, as long as the NPC is a duplicate of another NPC, the scope variables will be the same as another.

@4: When using deletearray command, the documentation is right, but also wrong. It should read:

*deletearray <array name>{[<first value>],<how much to delete>};

This is because, when a start & end value is omitted, it defaults to:   deletearray <arrayname>[0],<script_max_array_size>;

So it should be completely erasing your array from existence.

 

 

Hope that helps D: and anyone else who feels I am wrong on a certain matter, please don't hesitate to correct me !!

Edited by GmOcean
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

I don't really wanna go all in-depth but yeah I'm pretty sure you can... Because I've done it before...

copyarray .some_array[0], getvariableofnpc( .array_name[0], "NPC_A" ), 8;

If you want to have a more dynamic way to get the length just have the previous npc set that prior and call the length before the copyarray...

 

Also another really interesting way to do this seamlessly is to make NPC_B a duplicate of NPC_A remember duplicated npcs share NPC variables and thus arrays too.

 

Similarly but somewhat off-topic... You can also send arrays to functions by just passing the variable as a parameter.

copyarray .@some_array[0], getelementofarray( getarg(0), 0 ), getarraysize( getarg(0) );

It looks kinda funny but works! :P

  • Upvote 2
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  666
  • Reputation:   93
  • Joined:  04/27/12
  • Last Seen:  

@Skorm - Duplicates only share same NPC variables when they were set by the main npc right? Or did that change in a previous update, because eA didn't work like that and I haven't experimented with rA in that way yet D:

 

Edit: It seems they do indeed share the same values when using a duplicate NPC D: Changed my frist post, to direct to Skorm's for #3 =P

Edited by GmOcean
  • Upvote 2
Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

@Skorm - Duplicates only share same NPC variables when they were set by the main npc right? Or did that change in a previous update, because eA didn't work like that and I haven't experimented with rA in that way yet D:

 

That's really interesting, I can't remember if I've tested that. I always work from the the main npc and branch out...

 

Edit: Yup they do indeed xD

prontera,157,183,4	script	Array_test#401	859,{
	if( "401" == strnpcinfo(2) )
		dispbottom ""+.npc_variable[4];
	else
		set .npc_variable[4], atoi(strnpcinfo(2));
	end;
	
OnInit:
	set .npc_variable[4], 900;
}

prontera,155,183,5	duplicate(Array_test#401)	Array_test#502	406
  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...