Jump to content
  • 0

Any suggestion for matrix?


Kavaline

Question


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.01
  • Content Count:  18
  • Reputation:   1
  • Joined:  02/15/20
  • Last Seen:  

Hi, I need write this kind of script:



setarray .arrayAn[1], 1, 2, 3, 4, 5;
setarray .arrayA$[1], "a", "b", "c", "d", "e";
setarray .arrayBn[1], 6, 7, 8, 9, 10, 11;
setarray .arrayB$[1], "f", "g", "h", "i", "j", "k";
setarray .arrayCn[1], 12, 13, 14, 15;
setarray .arrayC$[1], "l", "m", "n", "o";

.@value = rand(1,getarraysize(.arrayAn));
.resultn[1] = arrayAn[.@value];
.result$[1] = arrayA$[.@value];
   
.@value = rand(1,getarraysize(.arrayBn));
.resultn[2] = arrayBn[.@value];
.result$[2] = arrayB$[.@value];
     
.@value = rand(1,getarraysize(.arrayCn));
.resultn[3] = arrayCn[.@value];
.result$[3] = arrayC$[.@value];

Have any way to use matrix or other solution, doing something like this:

setarray .arrayn[1][1], 1, 2, 3, 4, 5;
setarray .array$[1][1], "a", "b", "c", "d", "e";
setarray .arrayn[2][1], 6, 7, 8, 9, 10, 11;
setarray .array$[2][1], "f", "g", "h", "i", "j", "k";
setarray .arrayn[3][1], 12, 13, 14, 15;
setarray .array$[3][1], "l", "m", "n", "o";

for (.@i = 1; .@i <= 3; ++.@i) {
	.@value = rand(1,getarraysize(.arrayn[.@i]));
	.resultn[.@i] = arrayn[.@i][.@value];
	.result$[.@i] = array$[.@i][.@value];
}

This is a script with testing values that I'm using to find a solution, my original script will needs 100 loops in this case (and will only use integers, for IDs and numbers, in non logical or consecutive order), and without matrix is really unfair. Have another option that help me?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 1

  • Group:  Content Moderator
  • Topic Count:  55
  • Topics Per Day:  0.02
  • Content Count:  1676
  • Reputation:   702
  • Joined:  12/21/14
  • Last Seen:  

---------------------------------------

*setd "<variable name>",<value>{,<char_id>};

Works almost identically as set, except the variable name is identified as a string
and can thus be constructed dynamically.

This command is equivalent to:
	set getd("variable name"),<value>;

Examples:

	setd ".@var$", "Poporing";
	mes .@var$; // Displays "Poporing".

	setd ".@" + .@var$ + "123$", "Poporing is cool";
	mes .@Poporing123$; // Displays "Poporing is cool".

NOTE:
	'char_id' only works for non-server variables.
	Player with Character ID 'char_id' must be online.

---------------------------------------

*getd("<variable name>")

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

This can also be used to set an array dynamically:
	setarray getd(".array[0]"), 1, 2, 3, 4, 5;

Examples:

	set getd("$varRefence"), 1;
	set .@i, getd("$" + "pikachu");

---------------------------------------

example:

	setarray .@x,1,2;
	setarray .@x1,10,20,30,40,50;
	setarray .@x2,100,200,300,400,500;

	for(.@i=0;.@i<getarraysize(.@x);.@i++){
		for(.@m=0;.@m<getarraysize(getd(".@x" + .@x[.@i]));.@m++){
			debugmes "" + getd(".@x" + .@x[.@i] + "[" + .@m + "]");
		}
	}

 

Edited by sader1992
  • Upvote 1
  • Love 1
  • MVP 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  25
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   76
  • Joined:  06/13/13
  • Last Seen:  

i don't really see your direction of script but 2 dimensional array is not supported by script engine, use setd, getd or explode, implode

https://lmgtfy.com/?q=rathena+2d+array

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.01
  • Content Count:  18
  • Reputation:   1
  • Joined:  02/15/20
  • Last Seen:  

 

19 hours ago, Litro Endemic said:

i don't really see your direction of script but 2 dimensional array is not supported by script engine, use setd, getd or explode, implode

https://lmgtfy.com/?q=rathena+2d+array

I'm newbie in programming. I saw this post, but could't figure how to use, I got some errors, and by the time, I expected if another option was easier.

 

8 hours ago, sader1992 said:

---------------------------------------

*setd "<variable name>",<value>{,<char_id>};

Works almost identically as set, except the variable name is identified as a string
and can thus be constructed dynamically.

This command is equivalent to:
	set getd("variable name"),<value>;

Examples:

	setd ".@var$", "Poporing";
	mes .@var$; // Displays "Poporing".

	setd ".@" + .@var$ + "123$", "Poporing is cool";
	mes .@Poporing123$; // Displays "Poporing is cool".

NOTE:
	'char_id' only works for non-server variables.
	Player with Character ID 'char_id' must be online.

---------------------------------------

*getd("<variable name>")

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

This can also be used to set an array dynamically:
	setarray getd(".array[0]"), 1, 2, 3, 4, 5;

Examples:

	set getd("$varRefence"), 1;
	set .@i, getd("$" + "pikachu");

---------------------------------------

example:


	setarray .@x,1,2;
	setarray .@x1,10,20,30,40,50;
	setarray .@x2,100,200,300,400,500;

	for(.@i=0;.@i<getarraysize(.@x);.@i++){
		for(.@m=0;.@m<getarraysize(getd(".@x" + .@x[.@i]));.@m++){
			debugmes "" + getd(".@x" + .@x[.@i] + "[" + .@m + "]");
		}
	}

 

Works like a charm, this example was very helpful. The brackets needs to be in "" too, because of this, I got wrong results.

Solved question, can close the topic. Ty 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...