Jump to content


Photo

Need help with some AI and Variables.


  • Please log in to reply
18 replies to this topic

#1 Sejemus

Sejemus

    GMC Member

  • New Member
  • 11 posts
  • Version:GM8

Posted 24 February 2012 - 08:07 PM

Hello there.

I have a problem with GM 8.1.

The Var problem:

In the game start menu i have a controller.

Menu controller create event: set variable gun = 0. (TO object player. NOT self)

In player.

in key press ctrl: if variable gun = 1 then create instance bullet.
also in key press ctrl: if variable gun = 2 then create instance bullet2
also in key press ctrl: if variable gun = 3 then create instance bullet3

In a shop menu i have a button that have the following:

left mouse button (on buy gun button): set variable gun = 1 and change instance to (upgrade gun button)
left mouse button (on upgrade gun button): if gun is higher than 2 then set gun to 3 and show massage "gun at maximum" ELSE set gun = 1 RELATIVE.

Again gun variable IS on the player on both buttons.

Problem: When i start the game. I go to the shop and click the "Buy gun button" it tells me that it is at maximum already.
And if i click ctrl. It says that gun is a unknown variable?? (here is the error report:

[ERROR in
action number 1
of Key Press Event for <Ctrl> Key
for object obj_player:

Error in expression:gun
position 1: Unknown variable gun])


The AI problem:

I don't know what information to give here. So i give all of it.
But the problem is that when it jumps and hit the side of a block it gets stuck. It have a sprite that are a square so it isn't because the pixels are bugging

obj_enemy

(Event) [Parts]

(Create): [code:
direction=floor(random(2))*180;
speed=4; hspeed *=-1;
ShootTimer=0 - End of code
set variable hp = 50]

(Step): [code:
if obj_player.x>x && distance_to_object(obj_player)<300
{
hspeed=4;
}
if obj_player.x<x && distance_to_object(obj_player)<300
{
hspeed=-4;
}
ShootTimer += 1
if (ShootTimer mod 60 = 59)
{
if distance_to_object(obj_player)<100
{
instance_create(x,y,obj_bullet)
hspeed=0;
}
} - End of code
, if a positions is colitions free then set gravity 270, 0.5 else set gravity 270, 0. if hp is smaller than 1 then destroy instance self.

(Collision with wall): move to contact direction: direction maximum: 12 against solid objects, set vert. speed 0

(Collision with wall2(this is where the problem is)): move to contact direction: direction maximum: 12 against solid objects, set vert. speed 0

(Draw): draw sprite spr_enemy

I hope someone can help me :). Thanks. Sry if this is in the wrong section. But I didn't really think it should be anywhere else?. And sry for my bad english.
  • 0

#2 Madales

Madales

    GMC Member

  • GMC Member
  • 62 posts
  • Version:GM8

Posted 24 February 2012 - 08:13 PM

[ERROR in
action number 1
of Key Press Event for <Ctrl> Key
for object obj_player:

Error in expression:gun
position 1: Unknown variable gun])


In the Create Event, you must define the first value for the variable gun ( gun=0 or gun=1 or ... )
  • 0

#3 Sejemus

Sejemus

    GMC Member

  • New Member
  • 11 posts
  • Version:GM8

Posted 24 February 2012 - 08:17 PM


[ERROR in
action number 1
of Key Press Event for <Ctrl> Key
for object obj_player:

Error in expression:gun
position 1: Unknown variable gun])


In the Create Event, you must define the first value for the variable gun ( gun=0 or gun=1 or ... )


But i don't want it to be reset every time i load a map. I want it to be saved.

EDIT: and the create variable is in the menu. a controller in menu (the var is linked to player)

Edited by Sejemus, 24 February 2012 - 08:18 PM.

  • 0

#4 Madales

Madales

    GMC Member

  • GMC Member
  • 62 posts
  • Version:GM8

Posted 24 February 2012 - 08:23 PM

Maybe, in the shop menu button, you've assigned the variable gun to the wrong object (if the menu button is an object different from obj_player)... Try to check!
  • 0

#5 Sejemus

Sejemus

    GMC Member

  • New Member
  • 11 posts
  • Version:GM8

Posted 24 February 2012 - 08:24 PM

Maybe, in the shop menu button, you've assigned the variable gun to the wrong object (if the menu button is an object different from obj_player)... Try to check!


No. it is linked to obj_player. I have checked all gun variables.
  • 0

#6 Nial8r

Nial8r

    GMC Member

  • New Member
  • 341 posts

Posted 24 February 2012 - 09:43 PM

Can you post the exact code for the controller and player?
  • 1

#7 lukew23

lukew23

    GMC Member

  • GMC Member
  • 276 posts
  • Version:Unknown

Posted 24 February 2012 - 09:50 PM

Basically, you have two options (if you want the gun var to be conserved). Either make the player object consistent, or make gun a global variable.
  • 0

#8 Thagrahn

Thagrahn

    GMC Member

  • GMC Member
  • 33 posts
  • Version:GM8

Posted 24 February 2012 - 11:04 PM

The AI problem:

I don't know what information to give here. So i give all of it.
But the problem is that when it jumps and hit the side of a block it gets stuck. It have a sprite that are a square so it isn't because the pixels are bugging

obj_enemy

(Event) [Parts]

(Create): [code:
direction=floor(random(2))*180;
speed=4; hspeed *=-1;
ShootTimer=0 - End of code
set variable hp = 50]

(Step): [code:
if obj_player.x>x && distance_to_object(obj_player)<300
{
hspeed=4;
}
if obj_player.x<x && distance_to_object(obj_player)<300
{
hspeed=-4;
}
ShootTimer += 1
if (ShootTimer mod 60 = 59)
{
if distance_to_object(obj_player)<100
{
instance_create(x,y,obj_bullet)
hspeed=0;
}
} - End of code
, if a positions is colitions free then set gravity 270, 0.5 else set gravity 270, 0. if hp is smaller than 1 then destroy instance self.

(Collision with wall): move to contact direction: direction maximum: 12 against solid objects, set vert. speed 0

(Collision with wall2(this is where the problem is)): move to contact direction: direction maximum: 12 against solid objects, set vert. speed 0

(Draw): draw sprite spr_enemy

I hope someone can help me :). Thanks. Sry if this is in the wrong section. But I didn't really think it should be anywhere else?. And sry for my bad english.


Alright, your problem here is one of two things.

If wall2 is a vertical wall object that is suppose to stop horizontal movement, then the horizontal movement is what needs to be set to 0.

If wall2 is meant to trigger the jump, then vertical speed needs to be set to a negative number.
  • 0

#9 Sejemus

Sejemus

    GMC Member

  • New Member
  • 11 posts
  • Version:GM8

Posted 25 February 2012 - 09:20 AM

Alright, your problem here is one of two things.

If wall2 is a vertical wall object that is suppose to stop horizontal movement, then the horizontal movement is what needs to be set to 0.

If wall2 is meant to trigger the jump, then vertical speed needs to be set to a negative number.


I have a invisible object to trigger the jump. So the wall shouldn't trigger the jump.

But i want the AI to jump over the wall2 objects automatic by the jump trigger. and NOT get stuck on the side of the wall2s.

Edited by Sejemus, 25 February 2012 - 09:22 AM.

  • 0

#10 Sejemus

Sejemus

    GMC Member

  • New Member
  • 11 posts
  • Version:GM8

Posted 25 February 2012 - 09:23 AM

Basically, you have two options (if you want the gun var to be conserved). Either make the player object consistent, or make gun a global variable.


i'll check it out.
  • 0

#11 Sejemus

Sejemus

    GMC Member

  • New Member
  • 11 posts
  • Version:GM8

Posted 25 February 2012 - 09:35 AM

Can you post the exact code for the controller and player?


I can try. But i have used a little code and then these icons stuff things.

controller create event: set score = 0 set lives = 0 set gun = 0

Player:

create: set health = 100 set var player = 0(this is a var i use to change the sprite when walking right and left and not moving.)

step: set's the grav. and checks the health and the lives.

collision with wall AND wall2: move to contact in direction, 12, solid only. Set the vert. speed 0

collision with bullet: set health = -10 relative. Destroy instance OTHER.

movement keys (wsad): just basic movement with jump to possision.

X-key: interacts with objects

Left mouse button [Not working]: Checks gun var. If = 1 create bullet. if = 2 create bullet (i change this when i have fixed the problem) if = 3 create bullet (also changing)

Draw: just drawing

That's about it.
  • 0

#12 Sejemus

Sejemus

    GMC Member

  • New Member
  • 11 posts
  • Version:GM8

Posted 25 February 2012 - 09:38 AM

If gun is global. Does it need to be set to the player also? and it's like global.gun right?
  • 0

#13 lukew23

lukew23

    GMC Member

  • GMC Member
  • 276 posts
  • Version:Unknown

Posted 25 February 2012 - 07:38 PM

If gun is global. Does it need to be set to the player also? and it's like global.gun right?

yes, every time it is referenced, it is global.gun But it only needs to be initialised in the first room by an object only in the first room so it doesn't reset.
  • 0

#14 Sejemus

Sejemus

    GMC Member

  • New Member
  • 11 posts
  • Version:GM8

Posted 25 February 2012 - 08:52 PM


If gun is global. Does it need to be set to the player also? and it's like global.gun right?

yes, every time it is referenced, it is global.gun But it only needs to be initialised in the first room by an object only in the first room so it doesn't reset.


Yea. So it's in menu controller: set var global.gun = 0 (Does it need to be linked to player? or self?)

then the rest.?
  • 0

#15 Sejemus

Sejemus

    GMC Member

  • New Member
  • 11 posts
  • Version:GM8

Posted 26 February 2012 - 08:26 PM

It won't work.. Nomatter what i do it won't check the variable global.gun. It dosen't give me an error. But it just does nothing??

Edited by Sejemus, 26 February 2012 - 08:26 PM.

  • 0

#16 111Studio

111Studio

    GMC Member

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

Posted 27 February 2012 - 01:32 AM

You need to provide us with the actual code that references to global.gun. Initialization, all checks, all modifications to the variable. Also, please place all code snippets in [.code] [./code] tags without the periods preceded by something like "Step Event of objPlayer" to designate where the code is located. Lastly, if you have more to say and no one has posted after you, please edit your previous post. If you're posting multiple times in order to use the quote function, you can put multiple quotes by clicking on the MultiQuote button or manually type [.quote=Username]Quoted text here[./quote]
  • 0

#17 Sejemus

Sejemus

    GMC Member

  • New Member
  • 11 posts
  • Version:GM8

Posted 27 February 2012 - 08:48 AM

You need to provide us with the actual code that references to global.gun. Initialization, all checks, all modifications to the variable. Also, please place all code snippets in [.code] [./code] tags without the periods preceded by something like "Step Event of objPlayer" to designate where the code is located. Lastly, if you have more to say and no one has posted after you, please edit your previous post. If you're posting multiple times in order to use the quote function, you can put multiple quotes by clicking on the MultiQuote button or manually type [.quote=Username]Quoted text here[./quote]


But I havn't used code to the var.'s. I use the built in stuff. I havn't used much code.
  • 0

#18 Nial8r

Nial8r

    GMC Member

  • New Member
  • 341 posts

Posted 27 February 2012 - 12:59 PM

In the player, use global.gun instead of gun.
  • 0

#19 Sejemus

Sejemus

    GMC Member

  • New Member
  • 11 posts
  • Version:GM8

Posted 27 February 2012 - 01:59 PM

In the player, use global.gun instead of gun.


I have tried that. It just won't check. No errors. But it doesn't work
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users