Jump to content
  • 0

OnInit question.


Lil Troll

Question


  • Group:  Members
  • Topic Count:  38
  • Topics Per Day:  0.01
  • Content Count:  276
  • Reputation:   24
  • Joined:  07/06/13
  • Last Seen:  

Hi guys, i just need to clarify something, is OnInit: works like this case below even no global vars used?

- script blahblah -1,{
OnInit:
setarray .blahblah,501,502,503,504,505;
setarray .blah,1,2,3,4,5;
end;
}
function script blah1 {
 for(.@i=0; .@i < getarraysize(.blahblah) .@i++){
  if(isequipped(.blahblah[.@i]) mes .@i+". "+getitemname(.blahblah[.@i)+" "+blah[.@i]+" ";
 }
return;
}
function script blah2 {
 for(.@i=0; .@i < getarraysize(.blahblah) .@i++){
  if(isequipped(.blahblah[.@i]) mes .@i+". "+getitemname(.blahblah[.@i)+" "+blah[.@i]+" ";
 }
return;
}
function script blah3 {
 for(.@i=0; .@i < getarraysize(.blahblah) .@i++){
  if(isequipped(.blahblah[.@i]) mes .@i+". "+getitemname(.blahblah[.@i)+" "+blah[.@i]+" ";
 }
return;
}
function script blah4 {
 for(.@i=0; .@i < getarraysize(.blahblah) .@i++){
  if(isequipped(.blahblah[.@i]) mes .@i+". "+getitemname(.blahblah[.@i)+" "+blah[.@i]+" ";
 }
return;
}
function script blah5 {
 for(.@i=0; .@i < getarraysize(.blahblah) .@i++){
  if(isequipped(.blahblah[.@i]) mes .@i+". "+getitemname(.blahblah[.@i)+" "+blah[.@i]+" ";
 }
return;
}
function script blah6 {
 for(.@i=0; .@i < getarraysize(.blahblah) .@i++){
  if(isequipped(.blahblah[.@i]) mes .@i+". "+getitemname(.blahblah[.@i)+" "+blah[.@i]+" ";
 }
return;
}
function script blah7 {
 for(.@i=0; .@i < getarraysize(.blahblah) .@i++){
  if(isequipped(.blahblah[.@i]) mes .@i+". "+getitemname(.blahblah[.@i)+" "+blah[.@i]+" ";
 }
return;
}
function script blah8 {
 for(.@i=0; .@i < getarraysize(.blahblah) .@i++){
  if(isequipped(.blahblah[.@i]) mes .@i+". "+getitemname(.blahblah[.@i)+" "+blah[.@i]+" ";
 }
return;
}
function script blah9 {
 for(.@i=0; .@i < getarraysize(.blahblah) .@i++){
  if(isequipped(.blahblah[.@i]) mes .@i+". "+getitemname(.blahblah[.@i)+" "+blah[.@i]+" ";
 }
return;
}

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  50
  • Topics Per Day:  0.01
  • Content Count:  1702
  • Reputation:   238
  • Joined:  09/05/12
  • Last Seen:  

Posted · Hidden by Euphy, August 28, 2013 - This is not correct.
Hidden by Euphy, August 28, 2013 - This is not correct.

That wouldn't work since OnInit will only trigger on the current script where they are. 

Link to comment

  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

OnInit will always run in an enabled script.

The issue is that you're setting NPC variables, which can only be directly referenced in that one NPC. Since your functions are external, you have to use the Getvariableofnpc command to access them.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  38
  • Topics Per Day:  0.01
  • Content Count:  276
  • Reputation:   24
  • Joined:  07/06/13
  • Last Seen:  

Thanks sir Euphy, am more enlightened. :)

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

Thanks sir Euphy, am more enlightened. :)

 

Alternatively including the function inside the npc will allow it to access npc variables... but you have to remember each function takes it's own scope... Also returning from a function inside an npc will reinstate your old scope variables, but the function will only be available to that npc.

 

prontera,152,152,5	script	Test	100,{
	function f_func;
	set .@Scope_Variable, 2;
	set .NPC_Variable, 1;
	f_func();
	dispbottom ""+.@Scope_Variable; //Will display 2.
	end;
	
	function f_func {
		dispbottom ""+.NPC_Variable; //Will display 1.
		dispbottom ""+.@Scope_Variable; //Will display 0.
		return;
	}
}
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...