Jump to content


Photo

XxTaLoNxX's constantly expanding list of questions


  • Please log in to reply
13 replies to this topic

#1 XxTaLoNxX

XxTaLoNxX

    GMC Member

  • New Member
  • 111 posts

Posted 29 May 2011 - 06:09 AM

*Updated list of questions*

1) Currently I am having issues with getting an enemy's sprite animation to change based on it's direction OR based on the orientation of another object (player character). I'm pretty bad at reading//writing code so if you could help me based on the GM 8 Pro drag n' drop icons, I would appreciate that very much.

2) How do I add "items" to a "chest"? And then if there were two chests, 1 would have a... health potion, while the other a set amount of money.

*solved*3) I have this bit of code;

move_towards_point(obj_player.x,obj_player.y,2.);
if distance_to_object(obj_player) < 2
{
speed = 0;
}
in an attempt at having the enemy move towards the player character but to stop before it gets there... well that's not happening at all. It moves into the player character and gets stuck. I have even set up a collision event test in an attempt at getting it to test it's orientation relative to the PC but that's not working either


*solved*4) Let's say I want to change the following code to "global left mouse press"
if keyboard_check(vk_space) && can_attack = true && distance_to_object(obj_enemy) < 1


*solved*5) I am currently having an issue getting my sprite animations to end after one full sequence. *semi-solved*
*solved*6) I can get the animations to end but I can't seem to get them to reference each-other to change to another sprite_index... hard to explain, if you would like to help with this PM me and I can fill in more details or link you to the .gmk
*solved*7) I am having difficulty with this piece of code, it's quite obvious what I am trying to do with it but it's not working...
if health < 1
    {
        instance_destroy() //not working as intended 
        can_attack = false //not working as intended
    }

*solved*8) When coding and typing 'else' I get an unexpected symbol error in the line... why? I've seen code use the 'else' function and not have the error. It's a minor inconvenience and if you would like to see my example I will gladly PM you the code that illustrates this.

Edited by XxTaLoNxX, 04 June 2011 - 06:41 PM.

  • 0

#2 XxTaLoNxX

XxTaLoNxX

    GMC Member

  • New Member
  • 111 posts

Posted 31 May 2011 - 11:18 PM

Instead of making a new topic, I'll just bump and add some more questions.

Lets say I want to change this to "global left mouse press";
if keyboard_check(vk_space) && can_attack = true && distance_to_object(obj_enemy) < 1

I have an attack animation that I set up on "global left mouse press" the problem I am having is that the animation loops, how do I get it to go through one full animation and then stop?
  • 0

#3 Joey McClenahan

Joey McClenahan

    GMC Member

  • New Member
  • 12 posts

Posted 01 June 2011 - 04:01 AM

event: animation end code: image_speed=0
  • 1

#4 XxTaLoNxX

XxTaLoNxX

    GMC Member

  • New Member
  • 111 posts

Posted 01 June 2011 - 07:11 PM

even: animation end code: image_speed=0


Thank you, but I am obviously an idiot and I have no idea how to implement this.

Edited by XxTaLoNxX, 01 June 2011 - 07:31 PM.

  • 0

#5 _207694

_207694

    GMC Member

  • New Member
  • 30 posts

Posted 01 June 2011 - 07:31 PM


even: animation end code: image_speed=0


Thank you, but I am obviously an idiot and I have no idea how to implement this.

You are not and Idiot >_> you are learning, just throw this in a step event, or create event :D
  • 1

#6 XxTaLoNxX

XxTaLoNxX

    GMC Member

  • New Member
  • 111 posts

Posted 02 June 2011 - 03:10 AM

Thanks _207694, but I'm not even sure how to write that code. So like I said, treat me like an idiot because I am absolutely 110% clueless as how to do it. As well as the previous questions in the thread.
  • 0

#7 Obj_Control

Obj_Control

    GM Mentor

  • New Member
  • 2561 posts

Posted 02 June 2011 - 03:39 AM

if distance_to_object(obj_player) > 2
{
move_towards_point(obj_player.x,obj_player.y,2);
}
Fixed
  • 1

#8 XxTaLoNxX

XxTaLoNxX

    GMC Member

  • New Member
  • 111 posts

Posted 02 June 2011 - 04:19 AM

if distance_to_object(obj_player) > 2
{
move_towards_point(obj_player.x,obj_player.y,2);
}
Fixed


Thank you! It works as intended now.

OK now to my attack animation sprite problems.

1) I have an event Global Mouse Pressed with an action (drag n' drop) Change sprite to player_mainattack.
2) I have tried setting up a check in the Step event;
if sprite_index = player_mainattack, subimage 4
{
image_speed=0
}

The thing is I am not sure if I am on the right track or if I am just doing it wrong... obviously it's not working and I have a feeling I wrote the check wrong...

EDIT: Eureka!!! I actually found the event "Animation End" under "Other" now I have this code under that event...

if sprite_index = player_mainattack
{image_speed=0}

Still not working though...

Edited by XxTaLoNxX, 02 June 2011 - 05:05 AM.

  • 0

#9 XxTaLoNxX

XxTaLoNxX

    GMC Member

  • New Member
  • 111 posts

Posted 03 June 2011 - 04:11 PM

Updated the OP with more questions and solved questions. So please reference that ;)
  • 0

#10 _207694

_207694

    GMC Member

  • New Member
  • 30 posts

Posted 04 June 2011 - 02:32 AM

-- 4. replace you keyboard_check with this:
mouse_check_button(mb_left)

--5/6. You are using Animation End event correct? well add ?step? event to it, and put you if x {spite_index = x; image_speed = x; x = x; y = y;} whatever got the idea??

-- 7. should be:
//step event =>
if health <= 0 {
    instance_destroy(); 
    can_attack = false;  // in create event you need to define what this does..
}
-- 8.
if blah = ahs {
    blah = balh
} else if blah = usy {
    blah = fwe
}


Edited by _207694, 04 June 2011 - 02:41 AM.

  • 1

#11 XxTaLoNxX

XxTaLoNxX

    GMC Member

  • New Member
  • 111 posts

Posted 04 June 2011 - 09:22 AM

-- 4. replace you keyboard_check with this:

mouse_check_button(mb_left)


Thank you!

--5/6. You are using Animation End event correct? well add ?step? event to it, and put you if x {spite_index = x; image_speed = x; x = x; y = y;} whatever got the idea??


I actually figured this out a few minutes ago and just came by to update this list, thank you very much though.

-- 7. should be:

//step event =>
if health <= 0 {
    instance_destroy(); 
    can_attack = false;  // in create event you need to define what this does..
}


I have can_attack as a defined variable in the create event. I found the issue with the code... I forgot the ';' symbol... I'm a dunce lol. Thank you.

-- 8.

if blah = ahs {
    blah = balh
} else if blah = usy {
    blah = fwe
}


o_O going to have to study and decipher this lol.

*updated OP* I still have two unanswered questions, the main focus on programming hurdles now is question #1. I can provide a link to my .gmk if you guys need to take a look at it to answer the question. The goal is to get the enemies' sprites (animated) to change based on their relative orientation to the player object. So if the player_object is to the right of the enemy the sprite changes to the right facing sprite (animation) and etc...

Edited by XxTaLoNxX, 04 June 2011 - 09:35 AM.

  • 0

#12 _207694

_207694

    GMC Member

  • New Member
  • 30 posts

Posted 04 June 2011 - 06:03 PM

o_O going to have to study and decipher this lol.

*updated OP* I still have two unanswered questions, the main focus on programming hurdles now is question #1. I can provide a link to my .gmk if you guys need to take a look at it to answer the question. The goal is to get the enemies' sprites (animated) to change based on their relative orientation to the player object. So if the player_object is to the right of the enemy the sprite changes to the right facing sprite (animation) and etc...


Regarding the else thing. it depends on what you are doing, for example;


here we ask it to questions and check 'if' this then do this..
if x1 < x2  {
    x1 += 100;
} else if x2 < x1 {
    x2 += 100;
}

here we just check 'if' and then if it doesnt match anything in our 'if' question then x1 = this
if x1 < x2 {
    x1 += 100;
} else {
    x1 -= 100;
}

if you have anymore questions regarding the subject PM me, I can talk you through how exactly they differ.
This is just a quick example, I'll show you demonstrations through another programming language VBScript.

-- 1. I submitted a tutorial with a .gmk but its awaiting approval, but it would do exactly what you need have a look : AI Controller
that will also make your enemy move by them selfs based on obj_player.x and obj_player.y
download it and look you will see the switch statements in there you need to direct sprite changes based on there facing direction Posted Image

-- 2. I need a little more detail please, I guess i dont really get it.. read it a little confusingly :/

Edited by _207694, 04 June 2011 - 06:09 PM.

  • 1

#13 XxTaLoNxX

XxTaLoNxX

    GMC Member

  • New Member
  • 111 posts

Posted 04 June 2011 - 06:39 PM

You're right #2 is very confusing so I will just remove that question and replace it with another that just popped up.
  • 0

#14 _207694

_207694

    GMC Member

  • New Member
  • 30 posts

Posted 04 June 2011 - 06:50 PM

You're right #2 is very confusing so I will just remove that question and replace it with another that just popped up.




-- 1. incase my server is being slow, or not responding heres the switch statement i made to decide on running and facing direction
be sure to adjust your sprites and objects as well as the distance measured..

step:

if obj_player.x > obj_cpu.x && distance_to_object(obj_player) < 50 {
    facing_dir = 0;
}
if obj_player.x > obj_cpu.x && distance_to_object(obj_player) > 50 {
    facing_dir = 1;
} 
if obj_player.x < obj_cpu.x && distance_to_object(obj_player.x-1) < 50 {
    facing_dir = 2
} 
if obj_player.x < obj_cpu.x && distance_to_object(obj_player.x-1) > 50 {
    facing_dir = 3;
}



switch (facing_dir) {
    
    case 0:
        move_towards_point(obj_player.x,obj_player.y,2);
        sprite_index = spr_cpu_walking_R;
        image_speed = .5;
    break;
        
    case 1:
        move_towards_point(obj_player.x,obj_player.y,8);
        sprite_index = spr_cpu_run_R;
        image_speed = 1;
    break;
    
    case 2:
        move_towards_point(obj_player.x,obj_player.y,2);
        sprite_index = spr_cpu_walking_L;
        image_speed = .5;
    break;
    
    case 3:
        move_towards_point(obj_player.x,obj_player.y,8);
        sprite_index = spr_cpu_run_L;
        image_speed = 1;
    break;
}
create:
//if your cpu is on the right it 1 to make him run towards him, if hes on the left set it to 3 =>
facing_dir = 1;

-- 2. Im not sure how to add values to arrays YET, thats what im working on in GML atm, but you would def want to use an array to set possible contents of chest..

//step event of the chest??
global.coins[0] = 100; //current amount of coins



// I belive this needs to be in the create event for obj_chest
global.chest_items[0,0] = potion;
global.chest_items[0,1] = coins[0] += 15; //amount here

but this is as much as i can help on that one, hopefully some one else can reply with help on that because i need to know how to add data to arrays too..

but also if you are wanting to have the chest randomly give one of the two you need:

var n;
    n = round(random(1));  // the number here needs to be equal to the amount of items in the array
    rec_item = global.chest_items[n]);

EDIT:

ini files my friend :D thats the secret to writing to the value but there has to be another way you the person playing your game will be able to edit the values.. unless you made the names inside the ini file jargon.. ?_?

Edited by _207694, 04 June 2011 - 07:16 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users