Welcome Guest ( Log In | Register )

[ Big| Medium| Small] -



Post new topic Reply to topic  [ 15 posts ] 
Ace of Spades
  Sat May 19, 2012 12:44 am
User avatar
Member

Location: Ohio
I'm working with RMXP, I'm hoping someone with scripting knowledge can help me out. For some quick background, this is for projectiles in an ABS I'm working on. Every time a projectile is fired, an event spawns, and the event ID is added to an array ($projectiles_array). Once the projectile has run its course, the even ID is erased from the array.

What I'm trying to do now with the collision detection, is check each event ID that is currently in $projectiles_array. For example, on a map with no events, the hero fires 3 arrows, meaning $projectile_array == [1, 2, 3] In pseudo-code, I'd need something like this:

Expand to see the code.


Can someone help me out?


Top Top
 Profile  
 

ZenVirZan
  Sat May 19, 2012 6:30 am
Member

Location: RMXP's Script Editor
Something along the lines of this?
Expand to see the code.

Then you'd just run something like:
Expand to see the code.


This is rough and untested, but should work, in theory.

_________________
Image


Top Top
 Profile  
 

Ace of Spades
  Sun May 20, 2012 10:35 pm
User avatar
Member

Location: Ohio
I appreciate the effort ZenVirZan, but I already have the collision code working. I'm working with a pixel-based script, so unfortunately event.x==projectile.x doesn't work. Basically what I did was give every object/enemy a certain width and height, and it'll actually use those dimensions to make hit-boxes. Anyways, I digress; perhaps I should post the full script I'm working with and maybe you or someone else can take a look.

Expand to see the code.

 
This script is called Sticky_Switches.  Basically what this does is allow you to put a comment into an event, and that event will automatically turn a switch on if certain conditions are met.  For example, commenting
Quote:
sticky_switch A -1 64 2
in an event would turn on local switch A if the player is within 64 pixels of the event (or two tiles), and the player is currently facing the event.  Once local switch A is on, it begins checking for melee collision, allowing me to save processing power by not constantly checking for collision on every single event on the map.  Hope that makes sense!
 
Anyways, the problem I'm having is that I need an option in the script to check if a projectile is in proximity.  So if I were to comment
Quote:
sticky_switch A projectile 64 0
inside an event, local switch A would turn on if any event ID that is currently in $projectiles_array is within 64 pixels of the event. The edits I've made are between lines 206 and 214, but the code I have there obviously isn't accomplishing what I need it to. I've just been experimenting, but I don't really know how to go about doing what I'm trying to accomplish. Anyone willing to take a look?


Top Top
 Profile  
 

BlueScope
  Mon May 21, 2012 7:47 am
The Third Man
[ranting about everything]
User avatar

Location: Germany
It sounds to me like all you need is this:
Expand to see the code.

Unless I get you totally wrong :ouch: But you kind of have that with your .each method...

_________________
Image

If you have a slightly positive memory of my Power Shift contest game,
you might be interested in this development screenshot...
More info about that soon!


Top Top
 Profile  
 

Ace of Spades
  Tue May 22, 2012 12:27 am
User avatar
Member

Location: Ohio
The method I wrote doesn't actually accomplish what I want it to, but it was the best I could come up with. Unfortunately my scripting knowledge is little to none, so I don't really understand how to accomplish what I'm trying to do, that just happened to be my best attempt. I'm confused with what you posted, where could I apply that in the script I posted?

I'm beginning to suspect this might not have been as simple of a question as I thought. At this point, I need the sticky switches script to check the event ID of each projectile, in the format of "$game_map.events[#{i}]", where i is any value currently listed in $projectiles_array (this would replace lines 209-213). Although the more I look at it, the more I realize their may be a problem elsewhere in the script that's holding me back.


Top Top
 Profile  
 

Ace of Spades
  Thu Jun 28, 2012 6:14 am
User avatar
Member

Location: Ohio
If anyone else is willing to take a look at this, I'd really appreciate it. I'm still trying to work around this, but ideally I'd love to get this to work. I don't feel it's too far out of the realm of possibility, if someone with some scripting knowledge could offer any suggestions.


Top Top
 Profile  
 

regi
  Thu Jun 28, 2012 7:34 pm
raptor king
User avatar
Global Moderator
The problem is in your each loop:
Expand to see the code.

You cycle through all the projectiles in the array, but each time you set it to e, the previous projectile is erased; so in the end, you're only checking for the last projectile in the array, rather than the whole array.

Try this instead:
Expand to see the code.


I changed two sections. The first part is where you made your edits; instead of setting e to one event, I made it an array that pushes (adds) each item in the projectiles array.

The second edit is in "def update_sticky_switches"; because it's an array, not a single event, I added a for loop that checks each event. If at the end of one check "v" (your switch check variable) is true, it will break and not bother to check the other elements in the array.

Let me know if that works out!

PS I helped indent the script for you; one of my pet peeves is messy code! (No worries, yours was relatively clean compared to the mess of XAS_ABS...)

_________________
regi's games | immerse

SCAVENGER
action-puzzle-RPG in which one can visualize the past
NEWT text-based adventures of a four-legged amphibian
OMNISIA time-traveling puzzle-RPG against the deadliest of foes


Last edited by regi on Sat Jun 30, 2012 11:17 pm, edited 1 time in total.
fixed syntax


Top Top
 Profile  
 

Ace of Spades
  Sat Jun 30, 2012 4:00 am
User avatar
Member

Location: Ohio
Thank you so much for you help Regi! That's what I love about this place, knowledgable, friendly users, and quick response times. However, I did run into some errors with the code you provided. I ran through a few scenarios, and these are the errors I came up with:

Checking for player
Quote:
line 246: No Method Error occured
undefined method 'values' for ["$game_player"]:Array


Checking when no projectiles are on the map
Quote:
line 246: No Method Error occured
undefined method 'values' for []:Array


Checked with two projectiles on the map, events 4 and 5
Quote:
undefined method 'values' for [$game_map.events[4]", "$game_map.events[5]"]:Array


I really appreciate you taking the time to look at this for me, it'd mean a lot to the progress of my game if I could get this working properly. I'd be able to put more interactive objects on each map with less lag processing it. If you could take another look to see what might have went wrong, I'd be really thankful.


Top Top
 Profile  
 

regi
  Sat Jun 30, 2012 11:20 pm
raptor king
User avatar
Global Moderator
Oops, you can get rid of the ".values" on line 246. I have a habit of adding that since I always work with arrays with events :x

I also fixed indentation from lines 213-216, if you care about that :P The new code is in my previous post, or you can make the edits yourself.

Let me know if that works!

_________________
regi's games | immerse

SCAVENGER
action-puzzle-RPG in which one can visualize the past
NEWT text-based adventures of a four-legged amphibian
OMNISIA time-traveling puzzle-RPG against the deadliest of foes


Top Top
 Profile  
 

Ace of Spades
  Wed Jul 04, 2012 8:31 pm
User avatar
Member

Location: Ohio
So I tried out the revised code, and two things I noticed:
It still isn't detecting the event id's that are projectiles, and when I try to check for both the player and a projectile in the same event, nothing will register. The player detection by itself still works fine though. There weren't any script errors this time around, but projectiles still aren't being detected.


Top Top
 Profile  
 

regi
  Wed Jul 04, 2012 10:38 pm
raptor king
User avatar
Global Moderator
Hrm... do you update $projectiles_array continuously? The way the script is currently set up, it only adds projectiles to the sticky switch whenever the event refreshes (each time it changes a page). This means if you add an event to $projectiles_array after the event has been set up, the new event won't register.

Try this:
Expand to see the code.

I added a @last_projectiles variable that is compared to $projectiles_array in the update function, which refreshes the event (and sticky-switch) if $projectile_array changes.

This still doesn't fix testing a player AND a projectile simultaneously, but if you let me know how you want the syntax to be, I can help you.

_________________
regi's games | immerse

SCAVENGER
action-puzzle-RPG in which one can visualize the past
NEWT text-based adventures of a four-legged amphibian
OMNISIA time-traveling puzzle-RPG against the deadliest of foes


Top Top
 Profile  
 

Ace of Spades
  Thu Jul 05, 2012 7:36 am
User avatar
Member

Location: Ohio
Okay, so it seemed you were correct about the problem. However, it still only detects projectiles that have entered the map before the event page is activated. The way I have everything set up now, is the collision of objects is detected with parallel process events. So every object (bush, rock, enemy, etc) that the player interacts with, is constantly checking for collision. The idea of this script is to have all those events set up as action key events on the first page, with a sticky switch that activates a local switch whenever the player or a projectile is in range, so they aren't constantly checking for collision. So essentially, yes, I'd need it to refresh what the event is checking for whenever a new projectile is added or removed. As far as the syntax goes, it doesn't matter if I could use two separate commands to check for both the player and projectiles, or if there would be one command to check for the player and projectiles in a two tile range simultaneously


Top Top
 Profile  
 

regi
  Thu Jul 05, 2012 6:44 pm
raptor king
User avatar
Global Moderator
Hopefully this should do it.
Expand to see the code.

The syntax for multiple events should be:
sticky_switch A -1,1,p 64 0

In this case, you'd be checking for the player, event 1, and all projectiles (make sure not to add any spaces between commas, or it'll think you're moving on). You can type either "p" or "projectiles"; I thought the former would be easier.

If you're wondering how, I changed the comment from adding the events themselves to simply adding the string "projectiles". Then in "update_sticky_switches", it checks if the array of events includes "projectiles"; if so, it deletes that and adds all the events in $projectiles_array. This way, there's no need to refresh the page, as it updates every frame, and should catch new projectiles.

_________________
regi's games | immerse

SCAVENGER
action-puzzle-RPG in which one can visualize the past
NEWT text-based adventures of a four-legged amphibian
OMNISIA time-traveling puzzle-RPG against the deadliest of foes


Top Top
 Profile  
 

Ace of Spades
  Sun Jul 08, 2012 10:08 pm
User avatar
Member

Location: Ohio
Well, I've been using the script for a couple days and everything appears to be working correctly! Hopefully I can start placing more objects on the map and not have to worry about it hurting the performance too much. I just want to thank you again for all your help, I really do appreciate it, and I'll certainly be placing your name in the credits.

In the mean time, if there's anything I can possibly help you with in return, feel free to let me know.


Top Top
 Profile  
 

regi
  Sun Jul 08, 2012 10:35 pm
raptor king
User avatar
Global Moderator
You're welcome, glad I could help! I don't think I need much help other than feedback on ideas and beta-testers, later, but if you're willing I can definitely give you a link to my private subforum.

_________________
regi's games | immerse

SCAVENGER
action-puzzle-RPG in which one can visualize the past
NEWT text-based adventures of a four-legged amphibian
OMNISIA time-traveling puzzle-RPG against the deadliest of foes


Top Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 


Who is online

Users browsing this forum: No users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Hosted By: