1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Execute Code vs Execute Script

Discussion in 'Programming' started by gamedev513, Jun 29, 2016.

  1. gamedev513

    gamedev513 Guest

    Hey everyone,

    Kind of a noob question, however, here it goes. What are the major differences between running code via Execute Code action vs. Execute Script action. What is the difference between running an Execute Code action with the following code in it:

    Code:
    scr_myscript();
    versus just selecting the Execute Script action for an object and selecting scr_myscript and leave arguments as 0?

    Thanks!
     
  2. NazGhuL

    NazGhuL NazTaiL

    Joined:
    Jun 20, 2016
    Posts:
    533
    with Execute Code you can add thing that are not script:

    Code:
    scr_myscript();
    
    x = 123;
    
    //comments...
    
    a = b+2;
     
  3. Fuzenrad

    Fuzenrad Guest

    With script you have arguments that can be previously set when you call, the 'Execute Code' is when you need a local code in a object, something simpler (not necessarily), both run at the same speed.
     
  4. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,122
    Using execute_code associates the code with the object, so when the object data is loaded into the PRAM, the code likely is too. When you use execute_script, the script is not necessarily loaded into the RAM at the same time as the object, so its code may not be readily available. Furthermore, when using execute_code, the code is performed instantly. When using script_execute, each of the arguments must first be loaded into the register(s) and saved to the RAM, even if they're all left blank, then the memory address of the script needs to be loaded into the register and the current address pushed to the stack. If the script hasn't be loaded into PRAM yet, it gets loaded, then the code in the script is executed. After the script has been executed, the previous address is retrieved from the stack and you go back to the object code.

    It's understandable why people would think they're practically equally fast, but all-in-all, execute_script is actually twice as slow as execute_code.
     
  5. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,926
    execute_script() lets you avoid repeating yourself, executing code lets you cut down on managing your script collection. I only ever use the execute-code action in my games nowadays, but a lot of those contains script calls. Long story short, why choose between cinnamon and butterscotch when you can have both? Both are useful, they're just useful in different situations.
     
  6. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,840
    [edit]
    I'm too drunk to post lol
     
    stainedofmind, hippyman, Keys and 2 others like this.
  7. Annoyed Grunt

    Annoyed Grunt Member

    Joined:
    Jun 20, 2016
    Posts:
    136
    I never use Execute Script, ever. Even if I need to execute a single script, I'll add a execute code and call the function.
    It makes it much easier to edit if I need to add more things.
     
  8. SoulTie

    SoulTie Guest

    This made me laugh super hard
     
    icuurd12b42 likes this.
  9. SoulTie

    SoulTie Guest

    because cinnamon tastes like spicy butt nuggets
     
  10. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,926
    execute_script() (the function, that is - I'm with you about always using code actions) is pretty handy, though, since you can use it to execute variable scripts, e.g. for script-based-state state machines. (Infinite State Machines? :p)
     
  11. hippyman

    hippyman Member

    Joined:
    Jun 20, 2016
    Posts:
    565
    I use execute script as a way to "sort of" have methods with objects.

    I made a special script called script_execute_array which is the same thing as script_execute but rather than putting your arguments in one at a time you put all your arguments in an array and then put the array as a whole in for the argument.

    Then the script figures out how many arguments there are and calls it accordingly. It's not perfect, but it's occasionally handy.

    Edit: I should mention that this is the ONLY time I use it though. I can't remember who tested it, but I vaguely remember somebody saying they did some tests and determined that execute_script is actually a good bit slower than execute_code. 100% hear-say right now and I don't plan on testing it so take that with a grain of salt.
     
  12. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,122
    Well i tested them last night. Hence i said e_s is 100% slower
     
  13. NicoDT

    NicoDT Member

    Joined:
    Jun 21, 2016
    Posts:
    237
    I'll show you the way I use script_execute(), it may help you

    Let's say that I have a grid with skills that looks something like this

    global.skills(0,0) = "thunder"
    global.skills(1,0) = scr_thunder
    global.skills(0,1) = "fire"
    global.skills(1,1) = scr_fire
    global.skills(0,2) = "ice"
    global.skills(1,2) = scr_ice

    With the following code, I could execute the skill's script easily

    Code:
    if (key_accept)
    {
      script_execute(ds_grid_get(global.skills,1, pos))   // pos = position of the cursor in the skills menu
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice