GML

I don't know about you guys, but for me, GML is the easiest to learn and use, although I don't know what this will mean for my future as an electrical/computer engineer :\

"Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
~The Bible of the Church of N
«1

Comments

  • Posts: 110
    I also have a quick GML question, I'm currently back at work at my own GM game, and I've hit a snag. To understand why the snag is happening, I want to run a test on the game, but when I try to run the experiment to test my hypothesis, all I get are Fatal Errors.

    Here's the issue. I want to draw lines between 2 points, or more, based upon different conditions, most notably, the value of the variable "control". I made sure the variable was initialized in the creation event, but every time I try running the game, it just keeps saying it can't find the value of the variable "control". I've tried googling it, and youtubing it, and even GM foruming it, nothing works, anyone got any ideas?

    BTW: the code that draws the line is in the draw event, which I believe is the main stickler.
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
  • I know jack about GML.
    "Gas giants don't discriminate. They have gas for everyone." -ASG
  • Posts: 110
    Well, frankly, that's more than me, I'm mostly recycling and modifying code Gheiter and others have fed me over the years (yum, tasty code).
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
  • Posts: 0
    What exactly is the code in each event? It's possible you've declared the variable in one script only as opposed to the object as a whole.
  • Posts: 0
    Post your code, I may be able to debug it and figure out what's wrong, along with explaining why it's wrong.
    /(?##~##)/
  • Posts: 0
    Bleh, I hate double posting, but I'm on a work computer and the edit function is broken BUT: Press the Object Information button for the glitched object and paste the code here from the window that pops up.
    /(?##~##)/
  • Posts: 110
    Information about object: obj_mk1secondary
    Sprite: spr_mk1secondary
    Solid: false
    Visible: true
    Depth: 0
    Persistent: false
    Parent:
    Mask:

    Create Event:

    execute code:

    dir=0
    dist=0
    depth=1
    rspeed=10
    shoot=(true)
    var bulletshoot
    mousecontrol=1 //controlled by mouse
    botcontrol=2 // controlled by AI, seeks Enemies
    var control=0 // does nothing
    Mk1and2control=4 //Mk1 & 2's un-turreted secondaries

    Begin Step Event:

    execute code:

    x = bolo.x+lengthdir_x(distance,dir+90+bolo.direction);
    y = bolo.y+lengthdir_y(distance,dir+90+bolo.direction);

    image_angle = direction

    if room=Mark3
    {control=1
    if collision_line(x+lengthdir_x(20,image_angle),y+lengthdir_y(20,image_angle),mouse_x,mouse_y,Mk3,true,true)
    {control=2}
    else
    {control=1}}
    else
    {control=4}

    if control=1
    {objectofinterest=noone
    pointofinterest=point_direction(x,y,mouse_x,mouse_y)
    direction += (sin(degtorad(pointofinterest-image_angle))*rspeed)
    Ang=(point_direction(x,y,mouse_x,mouse_y)-(image_angle))
    draw_line_color(x+lengthdir_x(20,image_angle),y+lengthdir_y(20,image_angle),mouse_x,mouse_y,c_blue,c_blue)}

    if control=2
    {objectofinterest=instance_nearest(x,y,enemy)
    if (collision_line(x+lengthdir_x(20,image_angle),y+lengthdir_y(20,image_angle),objectofinterest.x,objectofinterest.y,Mk3,false,true))
    {control=3}
    else
    {pointofinterest=(point_direction(x,y,(objectofinterest.y),(objectofinterest.x)))
    direction+=(sin(degtorad(pointofinterest-image_angle))*rspeed)
    Ang =(point_direction(x,y,objectofinterest.x,objectofinterest.y)-(image_angle))
    draw_line_color(x+lengthdir_x(20,image_angle),y+lengthdir_y(20,image_angle),objectofinterest.x,objectofinterest.y,c_green,c_green)}}

    if control=3
    {pointofinterest=point_direction(bolo.x,bolo.y,x,y)
    direction += sin(degtorad(pointofinterest-image_angle))*rspeed
    shoot=false}

    if control=4
    {pointofinterest=point_direction(x,y,mouse_x,mouse_y)
    direction += sin(degtorad(pointofinterest-image_angle))*rspeed}

    if (room=Mark3)
    {Ang =((pointofinterest)-(image_angle))
    if control=2
    {if (distance_to_object(objectofinterest)<=300 and Ang<=2)
    {shoot=true}
    else
    {shoot=false}}
    else
    {if Ang<=2
    {shoot=true}
    else
    {shoot=false}}}

    execute code:

    if (control=2 and shoot=true)
    {bulletshoot= 1}
    else{bulletshoot=0}

    if bulletshoot is equal to 1
    create instance of object obj_smallbullet at position (x,y) with speed 30 in direction direction
    Keyboard Event for Key:

    execute code:

    direction=point_direction(bolo.x,bolo.y,x,y)

    Mouse Event for Glob Right Button:

    execute code:

    if shoot=true
    {}

    create instance of object obj_smallbullet at position (x,y) with speed 30 in direction direction
    execute code:

    if shoot=false
    {}

    Draw Event:

    execute code:

    draw_self()

    if room=Mk3
    {if string(control)=1
    {draw_line_color(x+lengthdir_x(20,image_angle),y+lengthdir_y(20,image_angle),mouse_x,mouse_y,c_blue,c_blue)}
    if string(control)=2
    {draw_line_color(x+lengthdir_x(20,image_angle),y+lengthdir_y(20,image_angle),objectofinterest.x,objectofinterest.y,c_green,c_green)}}



    I'd like to think I'm really proud about the turret code, but it's still buggy, I was planning on using the lines to figure out why it didn't target what I wanted it to target.
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
  • Posts: 0
    Hmm, kinda hard to see without formatting. Are you using a combo of GML and the Drag N Drop commands? Also, could you paste the error report?
    /(?##~##)/
  • Posts: 110
    Sure Sure, and I'm using D&D only for spawning obj_smallbullet, it should have no bearing on the issue

    Error: ERROR!!! :: ############################################################################################
    FATAL ERROR in
    action number 1
    of Draw Event
    for object obj_mk1secondary:


    Push :: Execution Error - Variable Get -1.control(100033, -1)
    at gml_Object_obj_mk1secondary_Draw_0 (line 4) - {if string(control)=1
    ############################################################################################
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
  • Posts: 0
    "if string(control)=1"

    It's been a while since I've programmed anything, but I think this might have something to do with it. Strings and variables are separate things, and I believe you're trying to treat a string as an integer variable. Try just having "if control = 1" and see what happens.
    /(?##~##)/
  • Posts: 110
    I tried that, I only put in string when I saw someone else use it in a similar situation
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
  • Posts: 110
    Yep, I just checked, I get the exact same error message if I take out the string thing
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
  • Posts: 0
    "if room=Mk3"

    Perhaps this part? I'm pretty sure that wouldn't be the issue, but it could... try taking that out.
    /(?##~##)/
  • Posts: 0
    Ahhh, I think I found it. ( Still on work computer, edit function is borked )

    var control=0

    That's in your create event, and I could be wrong but I believe that's incorrect syntax for variable declaration. Remove the 'var' part, that should fix it. Don't remove the room part like I said in my previous post.
    /(?##~##)/
  • Posts: 110
    Still don't work, that was another change I did because I saw someone else use it in a similar situation.
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
  • Posts: 0
    Hmmm... perhaps I should mess around with the source file. What version of GM are you using?
    /(?##~##)/
  • Posts: 110
    GM Studio, V1.2.1130 Master Collection
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
  • Posts: 110
    I am unsure as to how I am supposed to upload it, "file type not supported"
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
  • Posts: 0
    Zip all of the files together and upload that. And damn, how did you get Master Collection? I have the same, thanks to this one guy who I know.
    /(?##~##)/
  • edited June 2014 Posts: 0
    Despite of it not working, "if string(control)=1" should indeed be be "if control = 1". You can't compare an integer with a string and expect a valid result. In order for it to work, both of the values must be strings, so it'd be " if string(control)="1" ". However, it'd be dumb to do this, as it's just a useless conversion.

    Same with "var control". The var keyword makes a variable only exist in the context it was initilized in (The create event, in this case), so make it just control, without the var.

    Fixing both of those should get rid of the error, as it states that the problem is with the 4th line in the draw event, which so happens to tell that a variable has not been initialized. That's because it no longer exists.
    This is still not our universe.
  • Posts: 0
    Forgive me if I sound a bit dumb, but isn't = used for setting a variable while == is used for comparison? I used to run into so many problems because of that.
  • Posts: 0
    In GML I've found it doesn't matter if you use = instead of == in an if statement.
    This is still not our universe.
  • Posts: 110
    Gheiter, even if I make those changes, it still yells at me, saying I'm doing it wrong. I'll zip it together when I get home, and anyone who wants can play with the source file
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
  • Posts: 110
    Here's the file, please be kind and not rip off any of my stuff, and just so you know, when you're testing stuff for level 3, just hit the "page up" key and you'll advance to the next level.
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
  • Posts: 0
    I'll mess around with it tomorrow and report back.
    /(?##~##)/
  • Posts: 110
    KK, thank you
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
  • Huh. I would have thought that var control fix would have done it. I'm downloading to investigate.
    Forgive me if I sound a bit dumb, but isn't = used for setting a variable while == is used for comparison? I used to run into so many problems because of that.
    This is correct in many languages. GML is flexible enough though where it's not crucial.
    How do you say no to someone who asks you to say no?
    - Random Question Number 289

    These Random Questions were not paid for by anybody.
  • edited June 2014 Posts: 110
    Hence the reason I'd like to think I'm doing rather well for myself, this is my first issue that my combined brainpower and internet searching could not fix. GML's flexibility is epic.
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
  • edited June 2014 Posts: 0
    First test run:

    I played through the game to attempt to see the context of how the error comes about. On level 3, after a few seconds of working with no errors, this happened:

    ############################################################################################
    FATAL ERROR in
    action number 1
    of Draw Event
    for object obj_mk1secondary:

    Push :: Execution Error - Variable Get 103823.y(1, -1)
    at gml_Object_obj_mk1secondary_DrawEvent_1 (line 7) - {draw_line_color(x+lengthdir_x(20,image_angle),y+lengthdir_y(20,image_angle),objectofinterest.x,objectofinterest.y,c_green,c_green)}}
    ############################################################################################

    Notice how the error is not about the variable called control? I'm investigating further. Here's an idea to try, though: In the create event of every object, put a 'control = 0' line. Does the error still happen?

    Second test run:

    ___________________________________________
    ############################################################################################
    FATAL ERROR in
    action number 1
    of Draw Event
    for object obj_mk1secondary:

    Push :: Execution Error - Variable Get 103813.y(1, -1)
    at gml_Object_obj_mk1secondary_DrawEvent_1 (line 7) - {draw_line_color(x+lengthdir_x(20,image_angle),y+lengthdir_y(20,image_angle),objectofinterest.x,objectofinterest.y,c_green,c_green)}}
    ############################################################################################

    This happened much sooner this time, and I also tried running with the GM:S debugger. It didn't run properly, so I had to close it. This seemed unrelated, though.

    After seeing this, I'm wondering if it's partly my Game Maker version. I'm still investigating.
    How do you say no to someone who asks you to say no?
    - Random Question Number 289

    These Random Questions were not paid for by anybody.
  • Posts: 110
    It is rather strange how your errors are called different things than mine. To me, that sounds like version difference, if you get frustrated, just go play the first two levels, as far as I'm aware, those aren't buggy at all, loads of fun, and I'd appreciate feedback on 'em.
    "Yae, though I walk through the valley of the shadow of death, I shall fear no evil, 'cause I broughts a Minigun"
    ~The Bible of the Church of N
Sign In or Register to comment.