November 27, 2021, 07:42:46 am

The Gang Garrison 2 Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

NOTICE: Due to a rise in bot activity, new posters need to be approved before posting.

Join the community Discord server!

Pages: [1] 2 3 ... 10

Author Topic: PrOF's programming questions  (Read 12968 times)

PrOF

  • Full Member
  • ***
  • Karma: 43
  • Offline Offline
  • Posts: 597
  • Sometimes a dev. Only sometimes
PrOF's programming questions
« on: March 07, 2017, 11:30:59 am »

WARNING: PROBABLY A STUPID QUESTION
So, I'm just getting started with GML, I know only Java and I thought It'd be fun
So I did a stupid workaround plugin for binding bubbles to keys, the I try to make another on and i get this:
Code: [Select]
object_event_add(Player, ev_step, '
if(global.myself.object.hp > 35){
show_message('AHHHHH');
}
');
___________________________________________
COMPILATION ERROR in file to be executed
Error in code at line 3:
    show_message('AHHHHH');
                  ^
at position 17: Symbol , or ) expected.
Now I'd like to know what I did wrong
« Last Edit: March 05, 2018, 12:50:05 pm by PrOF »
Logged

[FR]YB

  • 2013 Haxxy Award Winner
  • *
  • Karma: 28
  • Offline Offline
  • Posts: 642
  • There are 11 people playing holy sh
Re: The incompetent's cry for help
« Reply #1 on: March 07, 2017, 12:07:07 pm »

WARNING: PROBABLY A STUPID QUESTION
So, I'm just getting started with GML, I know only Java and I thought It'd be fun
So I did a stupid workaround plugin for binding bubbles to keys, the I try to make another on and i get this:
Code: [Select]
object_event_add(Player, ev_step, '
   if(global.myself.object.hp > 35){
      show_message('AHHHHH');
   }
');
___________________________________________
COMPILATION ERROR in file to be executed
Error in code at line 3:
         show_message('AHHHHH');
                  ^
at position 17: Symbol , or ) expected.
Now I'd like to know what I did wrong

You're using single quotes, both for your event script and for your show_message. It's interpreted like this:
object_event_add(Playerev_step'show_message('AHHHHH')');

If you use single quotes in object_event_add, you want to use double quotes for every other string within the script string.
object_event_add(Playerev_step'show_message("AHHHHH");');


EDIT: thought I'd mention, this is not really a stupid question. Plugin makers regularly pull their hair out because of strings. See Lorgan's workaround for menus, and saving stuff in ini files. There's a script within a script within a script, and the only workaround we have found so far is putting the single quote character into a variable, so that it becomes an actual single quote when the inner script is interpreted, but not the outer script.
Welcome to the very special hell of coding!
« Last Edit: March 07, 2017, 12:10:19 pm by [FR]YB »
Logged

Heapons

  • Junior Member
  • **
  • Karma: 6
  • Offline Offline
  • Posts: 128
  • Just a guy wandering on the internet.
Re: The incompetent's cry for help
« Reply #2 on: March 07, 2017, 01:12:17 pm »

hey! Pr0F why you don't try to participate to my best plugin contest :z5:
Logged

PrOF

  • Full Member
  • ***
  • Karma: 43
  • Offline Offline
  • Posts: 597
  • Sometimes a dev. Only sometimes
Re: The incompetent's cry for help
« Reply #3 on: March 07, 2017, 01:44:22 pm »

WARNING: PROBABLY A STUPID QUESTION
So, I'm just getting started with GML, I know only Java and I thought It'd be fun
So I did a stupid workaround plugin for binding bubbles to keys, the I try to make another on and i get this:
Code: [Select]
object_event_add(Player, ev_step, '
   if(global.myself.object.hp > 35){
      show_message('AHHHHH');
   }
');
___________________________________________
COMPILATION ERROR in file to be executed
Error in code at line 3:
         show_message('AHHHHH');
                  ^
at position 17: Symbol , or ) expected.
Now I'd like to know what I did wrong

You're using single quotes, both for your event script and for your show_message. It's interpreted like this:
object_event_add(Playerev_step'show_message('AHHHHH')');

If you use single quotes in object_event_add, you want to use double quotes for every other string within the script string.
object_event_add(Playerev_step'show_message("AHHHHH");');


EDIT: thought I'd mention, this is not really a stupid question. Plugin makers regularly pull their hair out because of strings. See Lorgan's workaround for menus, and saving stuff in ini files. There's a script within a script within a script, and the only workaround we have found so far is putting the single quote character into a variable, so that it becomes an actual single quote when the inner script is interpreted, but not the outer script.
Welcome to the very special hell of coding!

Code: [Select]
object_event_add(Player, ev_step_normal, '
if(global.myself.object.hp > 35){
show_message("AHHHHH");
}
');

___________________________________________
COMPILATION ERROR in file to be executed
Error in code at line 5:
   ');
   ^
at position 2: Wrong number of arguments to function or script.
What? is should read it like this:

object_event_add(Player, ev_step_normal, '
   if(global.myself.object.hp > 35){
      show_message(
"AHHHHH");
   }
'
);

___________________________________________
COMPILATION ERROR in file to be executed
Error in code at line 5:
   ');
   ^
at position 2: Wrong number of arguments to function or script.
Logged

[FR]YB

  • 2013 Haxxy Award Winner
  • *
  • Karma: 28
  • Offline Offline
  • Posts: 642
  • There are 11 people playing holy sh
Re: The incompetent's cry for help
« Reply #4 on: March 07, 2017, 02:01:42 pm »

object_event_add(Player, ev_step_normal, '
   if(global.myself.object.hp > 35){
      show_message(
"AHHHHH");
   }
'
);

___________________________________________
COMPILATION ERROR in file to be executed
Error in code at line 5:
   ');
   ^
at position 2: Wrong number of arguments to function or script.
Whoops, didn't notice that. Yeah, you need to specify the event subtype.

object_event_add takes 4 arguments: an object index, an event type, an event sub-type, and the event script. So your function call should be
object_event_add(Playerev_stepev_step_normal'string');

PrOF

  • Full Member
  • ***
  • Karma: 43
  • Offline Offline
  • Posts: 597
  • Sometimes a dev. Only sometimes
Re: The incompetent's cry for help
« Reply #5 on: March 07, 2017, 03:25:24 pm »

Thanks a lot :c1:
Appartently though I don't understand how global.myself.object, global.myself.object.hp and global.myself.object.maxHp work, probably because it's a pain to find variables in GM Studio (So yeah it still gives me an error)
Logged

Derpduck

  • 2011 Haxxy Finalist
  • *
  • Karma: 42
  • Offline Offline
  • Posts: 5770
Re: The incompetent's cry for help
« Reply #6 on: March 07, 2017, 03:37:37 pm »

global.myself.object is your Character object (the guy you control, basically). The others should be pretty clear, so I'm not sure what you are trying to do lol.
I would recommend using GM8 when doing any work with GG2 because that's what it's made in, GM:S is not totally compatible with it. If you want GM8 you'll have to ask someone here for it since you can't find it officially anywhere.

PrOF

  • Full Member
  • ***
  • Karma: 43
  • Offline Offline
  • Posts: 597
  • Sometimes a dev. Only sometimes
Re: The incompetent's cry for help
« Reply #7 on: March 07, 2017, 04:24:39 pm »

Code: [Select]
object_event_add(Player, ev_step, ev_step_normal, '
draw_text(700, 1000, global.myself.object.hp);
');


___________________________________________
ERROR in
action number 2
of  Step Event
for object Player:

Error in code at line 2:
    draw_text(700, 1000, global.myself.object.hp);
                                              ^
at position 45: Unknown variable hp

 ???
I feel embarrassed
So this is going to be basically a "PrOF tries to do something but everything goes wrong" topic btw
« Last Edit: March 07, 2017, 04:25:01 pm by PrOF »
Logged

ZaSpai

  • Ray Bann's Minion
  • *
  • Karma: 14
  • Offline Offline
  • Posts: 2239
  • "Eeh?! We're just allies!"
Re: The incompetent's cry for help
« Reply #8 on: March 08, 2017, 01:14:58 am »

Code: [Select]
object_event_add(Player, ev_step, ev_step_normal, '
draw_text(700, 1000, global.myself.object.hp);
');


___________________________________________
ERROR in
action number 2
of  Step Event
for object Player:

Error in code at line 2:
    draw_text(700, 1000, global.myself.object.hp);
                                              ^
at position 45: Unknown variable hp

global.myself.object.hp is a real (or is it a float?) and draw_text accepts a string as its third input, iirc you need to say string(global.myself.object.hp)

You need to add a conditional where if(global.myself.object != -1) since this code is going to call on every step of Player even if its Character is undefined hence the error

Also as an aside usually we keep draw code to the draw event (ev_draw)
I feel embarrassed
So this is going to be basically a "PrOF tries to do something but everything goes wrong" topic btw

(Fixed an unruly :quote: here)
« Last Edit: March 08, 2017, 01:15:40 am by ZaSpai »
Logged
Right behind you when you most expect it | classicwell master race

Phantom Brave

  • All Hail Classicwell
  • Moderator
  • *****
  • Karma: 70
  • Offline Offline
  • Posts: 12701
  • Another one --
Re: The incompetent's cry for help
« Reply #9 on: March 08, 2017, 01:17:41 am »

>Also as an aside usually we keep draw code to the draw event (ev_draw)

Drawing code won't even work anywhere else.
Logged

http://steamcommunity.com/id/wareya/
ladies and gentlemen i would like to announce that the fact of the matter is up that the fact of the matter is a fact and it matters

PrOF

  • Full Member
  • ***
  • Karma: 43
  • Offline Offline
  • Posts: 597
  • Sometimes a dev. Only sometimes
Re: The incompetent's cry for help
« Reply #10 on: March 08, 2017, 07:50:27 am »

Thanks a lot everyone, I'm going to be releasing my first
(click to show/hide)
plugin soon  :z6:
Logged

PrOF

  • Full Member
  • ***
  • Karma: 43
  • Offline Offline
  • Posts: 597
  • Sometimes a dev. Only sometimes
Re: The incompetent's cry for help
« Reply #11 on: March 08, 2017, 08:40:48 am »

Code: [Select]
___________________________________________
FATAL ERROR in
action number 1
of Trigger Event: <Deleted>
for object MovingPlatform:

COMPILATION ERROR in code action
Error in code at line 7:
    audio_play_sound(global.lowHealthWarn, 5, 0);
      ^
at position 5: Unknown function or script: audio_play_sound

https://docs.yoyogames.com/source/dadiospice/002_reference/game%20assets/sounds/audio_play_sound.html

Uhhhh...
« Last Edit: March 08, 2017, 08:41:25 am by PrOF »
Logged

Phantom Brave

  • All Hail Classicwell
  • Moderator
  • *****
  • Karma: 70
  • Offline Offline
  • Posts: 12701
  • Another one --
Re: The incompetent's cry for help
« Reply #12 on: March 08, 2017, 09:57:19 am »

That's game maker studio. GG2 doesn't use game maker studio.
Logged

http://steamcommunity.com/id/wareya/
ladies and gentlemen i would like to announce that the fact of the matter is up that the fact of the matter is a fact and it matters

PrOF

  • Full Member
  • ***
  • Karma: 43
  • Offline Offline
  • Posts: 597
  • Sometimes a dev. Only sometimes
Re: The incompetent's cry for help
« Reply #13 on: March 08, 2017, 10:25:27 am »

Tried using audio_play_sound because I was having skipping frames issues with sound_play
Turns out it's only GM not liking mp3s
Logged

PrOF

  • Full Member
  • ***
  • Karma: 43
  • Offline Offline
  • Posts: 597
  • Sometimes a dev. Only sometimes
Re: The incompetent's cry for help
« Reply #14 on: March 08, 2017, 10:34:06 am »

Tried using audio_play_sound because I was having skipping frames issues with sound_play
Turns out it's only GM not liking mp3s
NNNNNope
Still laggy on servers, fine when hosting
Logged
Pages: [1] 2 3 ... 10
 

Page created in 0.047 seconds with 36 queries.