Jump to content
  • 0

Calling a variable using an array


Question

Posted

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

11 answers to this question

Recommended Posts

  • 0
Posted
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)
  • 0
Posted

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

  • 0
Posted (edited)

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
  • 0
Posted

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

  • 0
Posted

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.

  • 0
Posted

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.
  • 0
Posted

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

  • 0
Posted

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.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...