BOB_ROX Posted December 17, 2009 Report Share Posted December 17, 2009 If any of you play sonic chronicles the dark brotherhood you'd see these icons that pop up near doors and stuff and you use the stylis pen to click it, Im trying to get that to work when near the door of tails workshop so you can go in and out. So basically it switches rooms. But I want it so its mouse click. Heres what I got so far for the draw event, But even this isnt working how I want it too if distance_to_object(objPlayer) = 50image_index=1if distance_to_object(objPlayer) = 100image_index=0[/CODE]Can anyone help me to get it to work? Link to comment Share on other sites More sharing options...
Spike Posted December 17, 2009 Report Share Posted December 17, 2009 Well, that will only work if you are exactly 50 pixels or exactly 100 pixels away. Try doing it like this: if (distance_to_object(objPlayer) < 50) {image_index=1} if (distance_to_object(objPlayer) > 49 && < 100) {image_index=0} Link to comment Share on other sites More sharing options...
BOB_ROX Posted December 17, 2009 Author Report Share Posted December 17, 2009 Its not working even when I changed the 100 and 50, and 49 to be smaller, And also the first code I tried with it the one you suggested it told me to remove the < on the second line coz it said it was unexpected. So have you got anything else? Link to comment Share on other sites More sharing options...
DimensionWarped Posted December 17, 2009 Report Share Posted December 17, 2009 When in doubt, post the code. Link to comment Share on other sites More sharing options...
BOB_ROX Posted December 17, 2009 Author Report Share Posted December 17, 2009 if (distance_to_object(objPlayer) < 10){image_index=1}if (distance_to_object(objPlayer) > 9 && 50){image_index=0}[/CODE]Thats what I got now, As I said I had to remove that < sign on the second line coz an error popped up with it saying Unexpected symbol, And as I also said I tried changing the numbers in the code coz when I first used it. It didnt show. So Yeah. Link to comment Share on other sites More sharing options...
Power Hedgehog Posted December 17, 2009 Report Share Posted December 17, 2009 if (distance_to_object(objPlayer) < 10){image_index=1}if (distance_to_object(objPlayer) > 9 && 50){image_index=0}[/CODE]Thats what I got now, As I said I had to remove that < sign on the second line coz an error popped up with it saying Unexpected symbol, And as I also said I tried changing the numbers in the code coz when I first used it. It didnt show. So Yeah.The second line of that code would pop up all kinds of errors because the syntax is wrong. It should look like:[CODE]if (distance_to_object(objPlayer) < 10){image_index=1}if (distance_to_object(objPlayer) > 9 && distance_to_object(objPlayer) < 50){image_index=0}[/CODE] Link to comment Share on other sites More sharing options...
Spike Posted December 17, 2009 Report Share Posted December 17, 2009 *facepalm* Agh. I can't believe I forgot that you can't just say "if (distance_to_object(objPlayer) > 49 && < 100)" without posting the "distance_to_object" again. Sorry, oops. Link to comment Share on other sites More sharing options...
BOB_ROX Posted December 17, 2009 Author Report Share Posted December 17, 2009 Im sorry, Power. But I tried that code and it STILL isnt working, as in showing up. I dont see why it isnt working. Link to comment Share on other sites More sharing options...
Vexus Posted December 17, 2009 Report Share Posted December 17, 2009 Maybe another function would yield better results. Try something like this: if ( instance_exists(objPlayer) ) { if( point_distance(x, y, objPlayer.x, objPlayer.y ) <= 50 )image_index = 1; else image_index = 0; } The first line is just to ensure that no errors come up during the start or end of a room. Link to comment Share on other sites More sharing options...
BOB_ROX Posted December 18, 2009 Author Report Share Posted December 18, 2009 Im sorry but that didnt work either, Idk why it isnt working, I swear I only got a code that only shows draw and thats the code Nothing else. Coz I know how I want the mouse click to work but I havent got that in the object yet, Im just worried about the appearing in the draw event. Link to comment Share on other sites More sharing options...
Spike Posted December 18, 2009 Report Share Posted December 18, 2009 Well, are you actually drawing the object? The only code you have shown us is that you change it's image_index. Link to comment Share on other sites More sharing options...
BOB_ROX Posted December 18, 2009 Author Report Share Posted December 18, 2009 Well Im guessing not, Coz I got the code in the draw event. And the sprite has 2 sub images, One thats invisible and one that is not, So its supposed to start out as invisible I kinda tried to get it so that when your close enough to it, It changes it. Or draws it and stuff. but since it didnt work I tried switching the 2 sub images around and it still doesnt come up with ANYTHING, No sprite, No nothing. Link to comment Share on other sites More sharing options...
Spike Posted December 18, 2009 Report Share Posted December 18, 2009 Well, how about you put the code in the step event, and instead of "image_index" you just use "visible=0" and "visible=1"? Link to comment Share on other sites More sharing options...
BOB_ROX Posted December 18, 2009 Author Report Share Posted December 18, 2009 Thanks it pops up now, I tried my mouse trick theory with it, It goes to the next room, Just...It dont bring sonic up It just comes up with an empty room, I only went with the varible on left mouse click. Can anyone help me out on that part? ^^' Link to comment Share on other sites More sharing options...
Vexus Posted December 18, 2009 Report Share Posted December 18, 2009 I can't believe I missed the fact that you put the code in the draw event. As for your new problem, global variables and creation codes should be able to solve the problem. First off, make 2 global variables (called 'global.teleport_x' and 'global.teleport_y') when you start the game. Next, go to the room editor of every map the player will be in, go to Settings > Creation Code, and add: instance_create(global.teleport_x, global.teleport_y, objPlayer); Then, press ctrl+right_click on your button object and select 'Creation Code', then add: teleport_x = a number; teleport_y = a number; This will give each button a unique set of customize without having to make new objects for each teleporter. Make sure those 2 variables are NOT defined in the button object's Create Event or it won't work. Now its just a case of adding the following code in the button's Mouse click code: global.teleport_x = teleport_x; global.teleport_y = teleport_y; That should do it. Link to comment Share on other sites More sharing options...
BOB_ROX Posted December 18, 2009 Author Report Share Posted December 18, 2009 For the teleport_x and y a number is that where its positioned on the level?, Or something else? Link to comment Share on other sites More sharing options...
Vexus Posted December 18, 2009 Report Share Posted December 18, 2009 'a number' stands for where you want the player to appear in the level. Link to comment Share on other sites More sharing options...
BOB_ROX Posted December 18, 2009 Author Report Share Posted December 18, 2009 I got 2 errors when I did what you told me ___________________________________________ ERROR in action number 1 of Step Event for object objPlayer: Error in code at line 2: if (player_collision_bottom_object(x, y, relative_angle, maskBig, objSpikeUp)) at position 43: Unknown variable relative_angle and the other ___________________________________________ ERROR in action number 1 of Step Event for object objBridge: Error in code at line 23: || !player_handle.ground) continue; at position 33: Unknown variable ground What do I do about these? Link to comment Share on other sites More sharing options...
Vexus Posted December 18, 2009 Report Share Posted December 18, 2009 This happens if the variables aren't defined in the create event, but the step event needs to use those missing variables immediately. This is usually a parenting problem. I'm not sure though... the template you use might handle spawning in a different way, where just using the "instance_create(x,y,obj)" function to spawn a player character doesn't complete the process. Link to comment Share on other sites More sharing options...
BOB_ROX Posted December 18, 2009 Author Report Share Posted December 18, 2009 So what do I do to fix it? Link to comment Share on other sites More sharing options...
Vexus Posted December 19, 2009 Report Share Posted December 19, 2009 That depends on the engine you use. First of all, make sure you know that all the variables (in this case 'ground' and 'relative_angle') are actually defined in the Create Event of objPlayer (or the child object if objPlayer has them). Then hunt down the code that normally spawns the player, and replicate that in the room Creation Code. Apart from that, I've got nothing without taking a closer look myself. Link to comment Share on other sites More sharing options...
BOB_ROX Posted December 19, 2009 Author Report Share Posted December 19, 2009 Basically Im using the Genesis engine, It has a starting position object for it that spawns the player but its only for when the menu has it, in this case the character menu to spawn sonic, Or tails or knuckles. And variables ground and relative_angle are in objSonic Link to comment Share on other sites More sharing options...
Spike Posted December 19, 2009 Report Share Posted December 19, 2009 If you want, you can send me the file and I could take a look for you. Link to comment Share on other sites More sharing options...
BOB_ROX Posted December 20, 2009 Author Report Share Posted December 20, 2009 Thanks. Do you have msn so I can send it over? Link to comment Share on other sites More sharing options...
Spike Posted December 20, 2009 Report Share Posted December 20, 2009 Yeah, no problem. My address is on my profile. Link to comment Share on other sites More sharing options...
Recommended Posts