Jump to content
  • 0

player variable +1


Vincent

Question


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Hi,

i try to make a script where a player var get every time +1. For some reason it dont work. Here is my script:

payon,111,110,5	script	Crazy Man	757,{

set player_point, player_point==0;

OnHit:
if (player_point==5)						
{ getitem 999,1;							 
}
else{
set player_point, player_point++;
mes ""+player_point+"";
goto L_change;
}
L_change:

mes "....";
end;

												}

 

Link to comment
Share on other sites

13 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

..in C not in script npc, and it's about script npc here ;)

My bad about that then, but Kenpachi said it correctly:

 

 

In that case *Athena has a bug. ^^

BTW; That's not just in C but in every other language I know.

These are standards which everybody should follow them.

Link to comment
Share on other sites


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

player_point++;
if( player_point == 5 ){
    getitem 999,1;
    mes "Get item.";
}else{
    mes ""+player_point;
}
close;

like this ?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Also dont work. Still the message say "1". points dont count higher....

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.00
  • Content Count:  764
  • Reputation:   220
  • Joined:  11/14/11
  • Last Seen:  

Just for clarification:

set player_point, player_point++;

 

You try to set the veriable player_point to the result of player_point++. The result is, that player_point still holds the same value. Why?

The result of an i++ operation wont change until the operation was finally executed while ++i knows the result while executing the operation.
I'm bad in explaining. Maybe this explains it better: http://stackoverflow.com/questions/24853/what-is-the-difference-between-i-and-i

 

Try this:

OnHit:
if (player_point==5)						
    getitem 999,1;
else
{
    player_point++; // set player_point, player_point + 1; would do the same
    mes ""+player_point+"";
    goto L_change;
}

 


 

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Also dont work. Maybe the varianle is set every time to "0" because of this:

 

payon,111,110,5	script	Crazy Man	757,{

set player_point, player_point==0;
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.00
  • Content Count:  764
  • Reputation:   220
  • Joined:  11/14/11
  • Last Seen:  

Yes, every time the player clicks on the NPC.

 

EDIT: Actually it's not always 0. It can be 1 if player_point equals 0. That's because player_point will have the value of the result of that comparison (player_point==0):

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Yes, every time the player clicks on the NPC.

 

EDIT: Actually it's not always 0. It can be 1 if player_point equals 0. That's because player_point will have the value of the result of that comparison (player_point==0):

And how can i fix it because if have to initialize the var befor i can use it or not?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.00
  • Content Count:  764
  • Reputation:   220
  • Joined:  11/14/11
  • Last Seen:  

No, in *Athena you don't have to declare/initialize variables, just use them. If you try to access a non-existing variable 0 (or an empty string) will be returned.

Link to comment
Share on other sites


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

You try to set the veriable player_point to the result of player_point++. The result is, that player_point still holds the same value.

You mean the variable player_point stay the same ?

player_point -> 0

set player_point, player_point++; -> 0 ?

Coz that's not true :P

 

prontera,155,181,5	script	test	100,{
	set @player_point, @player_point++;
	dispbottom "Click number "+ @player_point;
	end;
}

post-5984-0-40374800-1381171575_thumb.jpg

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

You try to set the veriable player_point to the result of player_point++. The result is, that player_point still holds the same value.

You mean the variable player_point stay the same ?

player_point -> 0

set player_point, player_point++; -> 0 ?

Coz that's not true :P

 

Actually, he is correct speaking about the instance scope.

But you are correct as well, because the variable check is located in another scope.

 

a = 1;
b = a++;
//b stores 1, not 2.
 
a = 1;
b = ++a;
//b stores 2

That's what Kenpachi means. During the execution command, a "var++" command is executed after the scope of the command it is located. Practically, as it is the same variable you are using, it makes no difference but to set an unneeded command; otherwise, if you work with more than 1 variable, it may land out in weird errors.

set a, a++;
//Is equal to:
set a, a;
a++;

 

 

 

Hi,

i try to make a script where a player var get every time +1. For some reason it dont work. Here is my script:

payon,111,110,5	script	Crazy Man	757,{

set player_point, player_point==0;

OnHit:
if (player_point==5)						
{ getitem 999,1;							 
}
else{
set player_point, player_point++;
mes ""+player_point+"";
goto L_change;
}
L_change:

mes "....";
end;

												}

It's really long I don't script for Ragnarok Online, so I don't really know if OnHit actually is a viable On-label event or not, what it does or if you recall it through a onevent command.

Just remember that each time you click on the NPC, you get your variable resetted. So, to trigger the getitem thing, you need to activate the "OnHit" label 5 times without clicking on the NPC.

Also, the L_change label is pretty much useless 'cause you jump in there in any case.

 

payon,111,110,5    script    Crazy Man    757,{

set player_point, player_point==0; //I don't know if you need a reset here... but well...

OnHit:
    player_point++;
    if( player_point == 5 )                        
        getitem 999,1;                             
    dispbottom "...";
    end;
}
Link to comment
Share on other sites


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

That's what Kenpachi means. During the execution command, a "var++" command is executed after the scope of the command it is located.

..in C not in script npc, and it's about script npc here ;)

prontera,150,182,5	script	jiknju	56,{
	.@b = 1;
	.@a = .@b++;// set b before a
	dispbottom .@a +": is a";
	dispbottom .@b +": is b";
	end;
}

post-5984-0-28728700-1381189502_thumb.jpg

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.00
  • Content Count:  764
  • Reputation:   220
  • Joined:  11/14/11
  • Last Seen:  

You try to set the veriable player_point to the result of player_point++. The result is, that player_point still holds the same value.

You mean the variable player_point stay the same ?

player_point -> 0

set player_point, player_point++; -> 0 ?

Coz that's not true :P

 

prontera,155,181,5	script	test	100,{
	set @player_point, @player_point++;
	dispbottom "Click number "+ @player_point;
	end;
}

In that case *Athena has a bug. ^^

BTW; That's not just in C but in every other language I know.

static void Main(string[] args)
{
    int x = 0;
    int y = 0;
    for (int i = 0; i < 10; i++)
    {
      y = x++;
      Console.WriteLine(y.ToString());
    }
    Console.ReadKey();
}
http://www.pic-upload.de/view-20951045/08.10.jpg.html

 

If it's desired to work like you said, the operation should be ++i instead of i++. These are standards which everybody should follow them.

static void Main(string[] args)
{
    int x = 0;
    int y = 0;
    for (int i = 0; i < 10; i++)
    {
      y = ++x;
      Console.WriteLine(y.ToString());
    }
    Console.ReadKey();
}
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Thanks to all poster. Fixed it by using the var without ini 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...