Jump to content
  • 0

About Goto, DoEvent and Functions differences


Brainstorming

Question


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   4
  • Joined:  01/22/13
  • Last Seen:  

Well, I'm working with my first project and there´s a something that I can't understand completely which are the differences between:

- Goto

- DoEvent / DoNpcEvent

- Functions

Well. I know Goto must be avoided if possible, but I find it really similar to DoEvent / DoNpcEvent statements. In addition, Functions works pretty similar to DoEvent / DoNpcEvent statements (in both cases, you are creating a subroutine). So... I know that they are 3 different things for differents purposes, but at this time it's a bit blurry for me to see the limit between them.

Could someone explain me the differences and tell me wich one is the best option in each case? At least a little example to clarify mi mind.

I've looked for another support topics and also have checked Wiki and manual, but it's still confusing for me.

Thanx a lot and sorry for my bad english!

Link to comment
Share on other sites

5 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  379
  • Reputation:   304
  • Joined:  11/10/11
  • Last Seen:  

Goto sounds for me like a low level statement, so, as I thought, it's faster to emulate. I suppose that every While / For statement is disassembled to goto's sequence, so it was a surprise for me to read this in the manual:

You got it. All for(), while(), switch(), if, else, internal func(), ... are converted to label + goto/callsub + jump_zero on runtime.

But for keep the script readable it's better to not write the whole script using the low level statement (except if you have reasons like optimizations) :P

doevent, donpcevent are used to run another script instance. It's often used to start action on other script. Example: a script to manage all games in your server:

mes "Select the event to start";
switch( select("Capture the Flag","Nyan Cat Catcher", "First Man Dying") ) {
 case 1:
	  donpcevent "ctf::OnStartEvent";
	  break;

 ...
}

It's good to know that donpcevent will run the script after yours end (it's not multi-thread), to run it after continue you have to pause the script

donpcevent "todo::OnLol";
sleep2 1; // execute todo::OnLol before continue.
dowtfyouwant;

And functions/callsub I think you know them, it's used to avoid redundant, have fun with arguments, and return to the main script when finished.

Good luck for your project :)

  • Upvote 2
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

goto is not evil in *athena script engine

rather it is faster than for-loop or while-loop in certain situation

if you can read source you'll see these emulated script commands are also creating a temporary label in the source

the main difference in functions and donpcevent,

is donpcevent the able to start another script instance,

and function is able to send in arguments (donpcevent couldn't)

... its very hard to explain these kind of stuffs unless you are telling what kind of things that you want to do

these things can only learn from experiences, its not like you can understand them just by reading a guide

I'm working with my first project

try explain briefly what is your project about ... event script ? utility script ?
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   4
  • Joined:  01/22/13
  • Last Seen:  

Looks a bit clearly now.

Goto sounds for me like a low level statement, so, as I thought, it's faster to emulate. I suppose that every While / For statement is disassembled to goto's sequence, so it was a surprise for me to read this in the manual:

Note by FlavioJS: goto's are "evil" and should be avoided if possible (ò_ó)

About, DoEvent / DoNpcEvent and Functions, I understand that is better to use Functions if you're gonna write them in a separate script file, and DoEvent / DoNpcEvent are better if you are writting a subroutine in the same script file. It's right?

My project is an advanced utility NPC for Adminstration. My objective is to male easier to find users, information, ban, unban, etc. I think now atcommands are too many and, sometimes, a bit confusing, so an interactive menu is much more freandly. The FULL structure would be something like this:

Main Menu

|_ Look for Char

|_ Basic Info

|_ Build Info

|_ Family Info

|_ Guild Info

|_ Items

|_ Cart Items

|_ Storage Items

|_ Account Info

|_ All Chars in account

|_ Trading

|_ Trade

|_ Give Item

|_ Del Item

|_ Give Zeny

|_ Del Zeny

|_ Location

|_ Follow user

|_ Go to User position

|_ Invoke user

|_ Moderation

|_ Send Jail / Take out of Jail

|_ Mute / Unmute

|_ Block / Unblock

|_ IP Ban / IP Unban

|_ Security

|_Change Pass

|_ Change Mail

|_ Change Group

|_ Reset

|_ Reset Position

|_ Reset Model

|_ Reset Stats & Skills

|_ Reset Feeling

|_ Reset Homonculus

|_ Misc

|_ Level Up

|_ Job Level Up

|_ Changejob

|_ Killable

|_ Hom Hungry

|_ Hom Friendly

|_ Look for Account

|_ Basic Info

|_ Look Chars

|_ Look Storage

|_ Moderation

|_ IP Ban / Unban

|_ Security

|_ Change Pass

|_ Change Mail

|_ Change Group

|_ Look for Guild

|_ Leadership

|_ Changeleader

|_ Members

|_ List Castles

|_ Change Castle Ownership

|_ Location

|_ Warp Guildsmembers

|_ Moderation

|_ Ban / Unban All members.

|_ Misc

|_ Guild Level Up

|_ Spy Guild

|_ General Information

|_ Count users per Groups

|_ List Banned Users

|_ List Muted Users

|_ List MvP Card Owners

|_ WoE Manager (Open WoE Controller)

|_ Server Information

|_ Manage Server

|_ KickAll

|_ Exit Map Server

|_ Maps

|_ @Users

|_ Set Flag

|_ Look Map Info

|_ MOTD

|_ Show MOTD

|_ Reload MOTD

|_ NPC

|_ Hide NPC

|_ Show NPC

|_ Load NPC

|_ Unload NPC

I know is an ambitious project. First time for me scripting rAthena, but I've already worked with others languages (Assembler, Ladder, C++, Java, PHP, Javascript...). So, I want to do it as optimous as possible from the begining.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

doing something like this doesn't need to use donpcevent nor function

can be done entirely with goto or switch

note of some of the stuffs that you need to use source modification, and query_sql

like motd, spy guild ...

I have done something like this 5 years ago,

and I think most experienced scripters here also has made this kind of utility script on a live server before (but less feature than yours)

this kind of script usually don't share ... since its made specifically for a server

but well, since its your 1st script, I think you can learn from something from making this

especially, I learned a lot about script optimizing

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   4
  • Joined:  01/22/13
  • Last Seen:  

Thanks, you both helped me a lot. After reading quietly your answers and some write - try - rewrite work, It's clearly for me now.

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