Jump to content
  • 0

getd/getarg() and arrays


Stolao

Question


  • Group:  Developer
  • Topic Count:  48
  • Topics Per Day:  0.01
  • Content Count:  1443
  • Reputation:   337
  • Joined:  10/17/12
  • Last Seen:  

for(.@e = 0; .@e<4; .@e++){
	set .@r,rand(1,.L[3]);
	set .@s[.@e],getd(".M" +.@r)[.@r];
}

 ok my question is in the "set .@s[.@e]" part of the script, where should the "[.@r]" fall in this code should it fall within the getd() or after?

 

 

second question

getarg(0)[.@s]

 if getarg(0) is a menu name eg .H$, how would i pull out of the .H$ array via getarg

 

 

 

 

Edited by Stolao
Link to comment
Share on other sites

6 answers to this question

Recommended Posts


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

second question

getarg(0)[.@s]

 if getarg(0) is a menu name eg .H$, how would i pull out of the .H$ array via getarg

getelementofarray( getarg(0),<index> ) should work

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

for(.@e = 0; .@e<4; .@e++){
	set .@r,rand(1,.L[3]);
	set .@s[.@e],getd(".M" +.@r+"["+.@r+"]");
}

always inside  ;)

 

For the other one you can't use the whole array as an argument.

I think I heard somewhere that you can pass player array variables in functions but I never tried it

 

So you have two choices:

  • Either you use a @var[] array and then use it in your function
  • Or you pass the name of the array to your function so that it can get the variables using getvariableofnpc() and getd()

note that you'l have to give your array lenght to your function

 

for example :

-	script	YourNPCName	-1,{
callfunc "YourFuncName",".myarrayname",getarraysize(.myarrayname);
}

function	script	YourFuncName	{
	for (.@i = 0 ; .@i < getarg(1) ; .@i++)
		debugmes "val "+.@i+" : "+getvariableofnpc(getd(getarg(0)+"["+.@i+"]"),"YourNPCName");
	return;
}
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  81
  • Topics Per Day:  0.02
  • Content Count:  1654
  • Reputation:   583
  • Joined:  08/09/12
  • Last Seen:  

I don't quite understand your questions

for(.@e = 0; .@e<4; .@e++){
    set .@r,rand(1,.L[3]);
    set .@s[.@e],getd(".M" +.@r+"["+.@r+"]");
}
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  48
  • Topics Per Day:  0.01
  • Content Count:  1443
  • Reputation:   337
  • Joined:  10/17/12
  • Last Seen:  

 

I don't quite understand your questions

for(.@e = 0; .@e<4; .@e++){
    set .@r,rand(1,.L[3]);
    set .@s[.@e],getd(".M" +.@r+"["+.@r+"]");
}

 

let me add more detail then

setarray .M1,1,2,3;
setarray .M2,4,5,6;
setarray .M3,7,8,9;

for(.@e = 0; .@e<4; .@e++){
	set .@r,rand(1,.L[3]);
	set .@s[.@e],getd(".M" +.@r)[.@rr];
}

im trying to set .@s randomly from one of those 3 .M arrays, from a random point in one of those arrays

 

 

basically i want getd() to be from an array so how do i set the array index

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  81
  • Topics Per Day:  0.02
  • Content Count:  1654
  • Reputation:   583
  • Joined:  08/09/12
  • Last Seen:  

I don't know about your .L[3], and it looks like that Kurofly has answered your second question?

setarray .M1,1,2,3;
setarray .M2,4,5,6;
setarray .M3,7,8,9;

for (.@e = 0; .@e<4; .@e++) {
	set .@r,rand(1,.L[3]);
	set .@s[.@e],getd(".M"+.@r+"["+rand(getarraysize(getd(".M"+.@r)))+"]";
}
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  48
  • Topics Per Day:  0.01
  • Content Count:  1443
  • Reputation:   337
  • Joined:  10/17/12
  • Last Seen:  

 

second question

getarg(0)[.@s]

 if getarg(0) is a menu name eg .H$, how would i pull out of the .H$ array via getarg

getelementofarray( getarg(0),<index> ) should work

 

getd(getarg(0)+"["+.@r+"]");

is what i ended up going with for the 2nd part,  thanks guys :)

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...