Jump to content


Photo

Doing My Best Rattle Off Some Code On My Own, But I'm Not Seeing These Errors...


  • Please log in to reply
8 replies to this topic

#1 Christovix

Christovix

    GMC Member

  • New Member
  • 11 posts
  • Version:GM:Studio

Posted 27 March 2016 - 04:38 AM

So I've been working on a platformer, and I've just been setting everything up, variables and such. 

I kept getting errors (while I was coding, displayed at the bottom of the window, not while compiling), but was sure a lot of them didn't actually exist. So I compiled, and it showed me all of the errors that it had before. So I saved, and exited, and restarted GM. Them Immediately compiled, and it only showed me 2 errors. So... that's a thing. 

I've got this error:
"Error in Object obj_variables, Event Create, Action 1 at line 12, Position 2: symbol ) expected."
I'm not seeing any missing parentheses. Please advise...

(Sorry for the awkward quote/code thing goin on.)

 

///initialize global variables


//PLAYER Variable Note
    // if global.player = 1 (character 1)
    // if global.player = 2 (character 2)
        //Set at level start


//CONTROL Variables
global.right    = ((keyboard_check(vk_right))           || (keyboard_check(ord('D')))           || (gamepad_button_check(0, gp_padr)))
global.left     = ((keyboard_check(vk_left))            || (keyboard_check(ord('A')))           || (gamepad_button_check(0, gp_padl)))
global.up       = ((keyboard_check(vk_up))              || (keyboard_check(ord('W'))            || (gamepad_button_check(0, gp_padu)))
global.down     = ((keyboard_check(vk_down))            || (keyboard_check(ord('S')))           || (gamepad_button_check(0, gp_padd)))
global.jump     = ((keyboard_check_pressed(vk_space))   || (keyboard_check_pressed(ord('J')))   || (gamepad_button_check_pressed(0, gp_face1)))
global.shoot    =                                          ((keyboard_check_pressed(ord('I')))  || (gamepad_button_check_pressed(0, gp_face3)))
global.pickup   =                                          ((keyboard_check_pressed(ord('K')))  || (gamepad_button_check_pressed(0, gp_face2)))
global.itemuse  =                                          ((keyboard_check_pressed(ord('L')))  || (gamepad_button_check_pressed(0, gp_face4)))//Picked up an Item and HOLDING it, will change to 2, when item is dropped, change back to 1 global.carry = 1 //solid platforms up and down global.platform = ((obj_reg_ground) || (obj_reg_breakablebox) || (obj_reg_moveablebox) || (obj_reg_itembox))          //NUMERICAL VARIABLES global.hp = 3; //number of health points player has global.sp = 3; //number of science points player has global.awesome = 0; //awesome credits global.ammo = 0; //ammo global.life = 3; //lives //HUD AND MENU global.hearts = 3; //number of hearts player has access to global.science = 0; //number of science points player has access to
 

 

 

Another error: Error in Object obj_hank, Event Step, Action 2 at Line 3, Position 21: Unexpected symbol in expression.

 

 

///sprite changes based on movement


if ((hspd > 0) && (if (place_meeting(x, y+1, global.platform)))) { sprite_index = spr_hank_run };  // if moving horizontally on ground use RUN animation
else if ((hspd = 0) && (vspd = 0)) { sprite_index = spr_hank_idle }; //if not moving at all, use IDLE animation
else if (vspd !0) {sprite_index = spr_hank_jump} //if vertical speed is NOT ZERO use JUMP animation
else if ((global.shoot) && (!global.crouch)) { sprite_index = spr_hank_throw } //if shooting while not crouching use the THROW animation
else if ((!global.shoot) && (global.crouch)) { sprite_index = spr_hank_crouch } //if crouching and NOT shooting, use CROUCH animation 
else if ((global.shoot) && (global.crouch)) { sprite_index = spr_hank_crouchthrow } //if crouching and shooting, use the CROUCHTHROW animation
else if (global.carry = 2) {sprite_index = spr_hank_carry} //if physically holding an item, use CARRY animation 

 

 

 
 
On top of these errors, if you could tell me if this code is going to work (the control variables, and the sprite changes based on movement), or if there are any errors that the compiler won't pick up, that would be lovely. I'm kind of diving in and trying to write without constantly looking things up. Trying to use instinct, y'know?
In the second pile of code I posted here, the second 'else if" statement contains  "(vspd !0)" - I was wanting this to mean "if vspd is not equal to 0." Did I enter that correctly?
 
Thanks for your time!

Edited by Christovix, 27 March 2016 - 04:54 AM.

  • 0

#2 The Master

The Master

    GMC Member

  • New Member
  • 16 posts
  • Version:GM:Studio

Posted 27 March 2016 - 04:43 AM

Hmmmmm your codeing even better then me.

Well you must be doing something wrong some where.

I wish I could assist you but its been 4 or so years I did something so.

Still someone should assist you soon so.


  • 0

#3 BattleRifle BR55

BattleRifle BR55

    Let Live

  • GMC Member
  • 10316 posts
  • Version:GM:Studio

Posted 27 March 2016 - 04:57 AM

You have a lot of unnecessary brackets. Start removing them and you'll come across your error.

For your second thing, it's !=, not just the exclamation mark.
  • 0
Jmds8UL.png

#4 Christovix

Christovix

    GMC Member

  • New Member
  • 11 posts
  • Version:GM:Studio

Posted 27 March 2016 - 05:05 AM

You have a lot of unnecessary brackets. Start removing them and you'll come across your error.

For your second thing, it's !=, not just the exclamation mark.

"vspd !=0" 

 ...Correct?

For unnecessary brackets, are you telling me I can simply wrote the following:
 

else if global.shoot && !global.crouch { sprite_index = spr_hank_throw } 

Or do I need one set of brackets like this
 

else if (global.shoot && !global.crouch) { sprite_index = spr_hank_throw } 

  • 0

#5 BattleRifle BR55

BattleRifle BR55

    Let Live

  • GMC Member
  • 10316 posts
  • Version:GM:Studio

Posted 27 March 2016 - 05:24 AM

The second one is preferable (although both are accepted in GML), but I was getting more at things like this:

variable = (( keyboard_check() ) || ( keyboard_check() ))

Because you're wrapping each individual function and then everything together, you're making it hard to look at because there are so many brackets. I'd at least remove the individual wrapping.
  • 0
Jmds8UL.png

#6 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 13885 posts
  • Version:GM:Studio

Posted 27 March 2016 - 06:58 AM

Edit: Nevermind, I copy-pasted into GM and found the offending line.

 

(keyboard_check(ord('W')))


Edited by TheouAegis, 27 March 2016 - 07:01 AM.

  • 0

"The problem with object-oriented languages is that they've got all this implicit environment that they carry around with them. You wanted a banana but what you've got is a gorilla holding the banana and the entire jungle." -Joe Armstrong

 

"It goes against the grain of modern education to teach children to program. What fun is there in making plans, acquiring discipline in organizing thoughts, devoting attention to detail and learning to be self-critical?" -Alan Perlis

 

"Do not think about where you want to be and how to get there; think about what you want to do and how to do it." -Theou Aegis


#7 Christovix

Christovix

    GMC Member

  • New Member
  • 11 posts
  • Version:GM:Studio

Posted 28 March 2016 - 05:35 AM

Edit: Nevermind, I copy-pasted into GM and found the offending line.

 

(keyboard_check(ord('W')))

Thank youuuu. For some reason, going over my brackets a billion times looking for highlighted pairings didn't catch that.

I still cannot figure out the issue with this line. I've rewritten it many times to no avail. 

if (hspd > 0) && if (place_meeting(x, y+1, global.platform)) { sprite_index = spr_hank_run };  // if moving horizontally on ground use RUN animation

EDIT: Actually I discovered that if i comment out the first line of that code, the error moves into the next line, and it continues like this through that whole event. So I think I'm simply using the code incorrectly? The error is "unexpected symbol in expression" at position 2.

if ((hspd > 0) && (if (place_meeting(x, y+1, global.platform)))) { sprite_index = spr_hank_run };  
else if ((hspd = 0) && (vspd = 0)) { sprite_index = spr_hank_idle }; 
else if (vspd !0) {sprite_index = spr_hank_jump} 
else if ((global.shoot) && (!global.crouch)) { sprite_index = spr_hank_throw } 
else if ((!global.shoot) && (global.crouch)) { sprite_index = spr_hank_crouch } 
else if ((global.shoot) && (global.crouch)) { sprite_index = spr_hank_crouchthrow } 
else if (global.carry = 2) {sprite_index = spr_hank_carry} 

Edited by Christovix, 28 March 2016 - 05:41 AM.

  • 0

#8 Christovix

Christovix

    GMC Member

  • New Member
  • 11 posts
  • Version:GM:Studio

Posted 28 March 2016 - 06:13 AM

Okay I am ridiculous. 

if ((hspd > 0) && (if (place_meeting(x, y+1, global.platform)))) { sprite_index = spr_hank_run };

Does not need 2 if statements.


Edited by Christovix, 28 March 2016 - 09:10 PM.

  • 0

#9 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 13885 posts
  • Version:GM:Studio

Posted 29 March 2016 - 07:05 AM

if A && b

 

not

 

if A && if b

 

If you want to use 2 ifs, then it's

 

if A if B

 

which is ALMOST the same as

 

if A && B

 

but not quite.


  • 0

"The problem with object-oriented languages is that they've got all this implicit environment that they carry around with them. You wanted a banana but what you've got is a gorilla holding the banana and the entire jungle." -Joe Armstrong

 

"It goes against the grain of modern education to teach children to program. What fun is there in making plans, acquiring discipline in organizing thoughts, devoting attention to detail and learning to be self-critical?" -Alan Perlis

 

"Do not think about where you want to be and how to get there; think about what you want to do and how to do it." -Theou Aegis