Issue with a script?

Discussion in 'Programming' started by corwin22, Apr 28, 2018.

Tags:
  1. corwin22

    corwin22 Member

    Joined:
    Nov 18, 2017
    Posts:
    73
    I am trying to make it so that I use a script to call a block with custom commands using this script
    /// Scr_CustomBlock("Create","Step")
    instance_create_layer(64,64,"Funtions",obj_CustomBlock)

    global.CustomCreate = argument0;
    global.CustomStep = argument1;
    and the object uses this

    string_letters(global.CustomStep)
    inside the step event

    I type
    Scr_CustomBlock((undefined),("if (keyboard_check(vk_space)) {game_end()}"))
    and it doesn't do anythng when i press space?
     
  2. nacho_chicken

    nacho_chicken Member

    Joined:
    Jun 21, 2016
    Posts:
    330
    It seems to me what you're trying to do is execute code from a string. There was a function in old, pre-Studio versions of GameMaker that did this, but it is now obsolete. There is no way to do this currently.
     
  3. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,360
    String letters will just give you another string.

    It will not run any other code.

    If you want to run custom code like that, you need to write something to read, and interpret that string.
     
  4. corwin22

    corwin22 Member

    Joined:
    Nov 18, 2017
    Posts:
    73
    how would i make something to read it?
     
  5. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,360
    that is huge topic, and i would suggest you stay away from it for now.

    What is it you are trying to achieve, ultimately? there is probably a better way of achieving your goal.
     
  6. corwin22

    corwin22 Member

    Joined:
    Nov 18, 2017
    Posts:
    73
    I am trying to make it so i can use a script to summon a obj that has the text in the command in a step event so i can have 1 custom object instead of many for different senarios
     
  7. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,360
    there is a better way:

    Instead of writing you code in a string, create a script.
    Then, when you create your object, give it that script.
    in the object, you can run that script using script_execute.

    I have made a video tutorial about just this:
     

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