Jump to content
  • 0

Calling a variable using an array


Echoes

Question


  • Group:  Members
  • Topic Count:  34
  • Topics Per Day:  0.01
  • Content Count:  155
  • Reputation:   6
  • Joined:  03/30/13
  • Last Seen:  

Hello c:

 

Well, my doubt is, is there a way to call a variable (#Player_Variable) using an array (.@Array$[0]), and then set it to desired number?

 

I'm doing something like this, but doesn't work:

-	script	FromArrayToVariable	-1,{
	setarray @array_of_variables$[0],#Player_Variable01,#Player_Variable02;
	for(.@i=0; .@i<getarraysize(@array_of_variables$); .@i++)
		if(getd("@array_of_variables$["+(.@i)+"]") != 1)
			setd "@array_of_variables$["+(.@i)+"]",1;
	end;	
}

(example script)

 

 

Also, getting this error with the script:

[Error]: script:op_2: invalid data for operator C_NE
[Debug]: Data: string value="0"
[Debug]: Data: number value=1

I'm trying this script to avoid writing like 200+ lines :C

Help please :D

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

  • Group:  Developer
  • Topic Count:  36
  • Topics Per Day:  0.01
  • Content Count:  587
  • Reputation:   431
  • Joined:  01/26/16
  • Last Seen:  

if(getd("@array_of_variables$["+(.@i)+"]") != 1)

You are comparing a string variable to an integer. I think the fix below should work.

if(atoi(getd("@array_of_variables$["+(.@i)+"]")) != 1)
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  54
  • Topics Per Day:  0.01
  • Content Count:  513
  • Reputation:   83
  • Joined:  08/11/12
  • Last Seen:  

If you are storing it to an array which only contains numerical data types, remove the $ at the end of the variable name. For a more detailed explanation on variable and array types

https://rathena.org/wiki/Custom_Items

Link to comment
Share on other sites

  • 0

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

If you want to list the variables in an array, what about

-	script	FromArrayToVariable	-1,{
	setarray .@array_of_variables$[0],
		"#Player_Variable01",
		"#Player_Variable02";
	.@size_array = getarraysize(.@array_of_variables$);
	for ( .@i = 0; .@i < .@size_array; .@i++ )
		if ( getd( ".@array_of_variables$[" + .@i + "]") != 1 )
			setd ".@array_of_variables$[" + .@i + "]", 1;
	end;
}

but if you want to alter the variable of a player online you may use set <variable>,<expression>{,<char_id>}; and getvar <variable>,<char_id>; to retrieve the the variable

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  34
  • Topics Per Day:  0.01
  • Content Count:  155
  • Reputation:   6
  • Joined:  03/30/13
  • Last Seen:  

Hello, thank you all for responding.

 

@secretdataz

It did not retreive the variable value :C

 

@Ninja

Why custom item o.0 At least, didn't found any string usage information.

 

@Capuche

Well, adding those " " to the variables will make the script to retreive the entire variable name, no it's value :C

 

 

Well, was testing further and I found that this will call the numeric value of the variables:

	setarray @Var_Array$[0],	#Player_Variable01,
					#Player_Variable02,
					#Player_Variable03;
	for(.@i=0; .@i<getarraysize(@Var_Array$); .@i++){
		mes @Var_Array$[.@i];
		set @Var_Array$[.@i],1;
	} 

Now I need to set them to the desired number x_x (the set in that for doesn't work, or at least when talking to the NPC again it won't show a different variable value)

Edited by Echoes
Link to comment
Share on other sites

  • 0

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

Alright I don't understand what you want to do.. xD

But maybe with a sample of your script..

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  34
  • Topics Per Day:  0.01
  • Content Count:  155
  • Reputation:   6
  • Joined:  03/30/13
  • Last Seen:  

Alright I don't understand what you want to do.. xD

But maybe with a sample of your script..

Thank you for your efforts to help C: 

 

Now, my whole script is posted above, and now that I have the first part of the script done, I want to set those variables to numeric value 1, now they are 0 but I can't set them through script to 1 :C

Link to comment
Share on other sites

  • 0

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

 

Now, my whole script is posted above

Sorry. Where ?

 

It's the variables of the player attached to the script ?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  88
  • Reputation:   10
  • Joined:  01/15/16
  • Last Seen:  

i think that he want to use the variables as a pointer in C,  inside an array, so he can ask the value of the "original" variable and change it also, if im not wrong.

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

you didnt attach the script to an online players.

 

the best way to deal with variable value would be

  1. shut down server
  2. run SQL script  
     ( UPDATE `table` SET `value` = 1 WHERE `variable` LIKE '#variable' )
  3. done.
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  34
  • Topics Per Day:  0.01
  • Content Count:  155
  • Reputation:   6
  • Joined:  03/30/13
  • Last Seen:  

Well,

 

Sorry for the late responses on this, I have been working hard on my script and luckly I got everything working now, sadly without the array I was requesting help with :C

Will follow the suggestions you guys gave me so far and I will continue testing calling and editing #vars through arrays, thank you.

 

Aaaaand, I found this:

Resume of the allowed variable and array scopes
-----------------------------------------------

+==========+======+=======+
|VarType   | Norm | Array |
+==========+======+=======+
|#Int      | OK!  | FAIL! |
+----------+------+-------+

Maybe this has something to do with the success of calling and editing those #vars with an array e_e

 

Again, thank you guys for your help

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  88
  • Reputation:   10
  • Joined:  01/15/16
  • Last Seen:  

Ah and i recommend you to use setd and getd, maybe thats what are you looking for, you will have to adapt your script a little but it worth it.

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