~ combines stuff. Use it to add items into arrays.
eg.
let array1 = [a]
array2 = array1 ~ "b"
Now array2 is ["a", "b"]
If you want to mass add stuff, use ascent.
eg.
let array1 = []
ascent(i in 0.. 10){
array1= array1 ~ i
}
Now array1 is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].
I find that way hard to understand without a sample. x_x
I've looked into tuturials such as this http://dmf.shrinemaiden.org/wiki/index.php?title=Nuclear_Cheese%27s_Shot_Object_Tutorial , but the example script given is way too complicated to get a grip on.
I can somehow only make one bullet change properties, but when trying the same with multiple bullets, none respond to the changes.
I have this small test script here:
enemy=Obj_Create(OBJ_SHOT);
Obj_SetPosition(enemy,GetClipMinX+100,GetClipMinY+100);
Obj_SetSpeed(enemy,3);
Obj_SetAngle(enemy,90);
ObjShot_SetGraphic(enemy,RED01);
Obj_SetAutoDelete(enemy,true);
enemies = enemies ~ [enemy];
if(Obj_GetY(enemies)==200){
Obj_SetAngle(enemies,270);
}
But what I really want is:
-Have a new shot appear every X time or when an old one is deleted.
-Have them change direction so they move around the edges of the screen.
-Have them shoot stuff at you. :3
-The ability to individually make a change.
Yet all it can do now is making a long stream on bullets that only go downwards.
In the code you have there, I presume that
enemies is an array meant to hold a list of object shots you want to manipulate, correct?
You can't use the
Obj_GetY,
Obj_SetAngle, etc. commands on an array. Rather, you need to grab each item in the array and use the commands on each individually.
Within the tutorial you linked above, I gave a framework for using arrays of object shots. To translate it to the code example you have above, it would be something like this:
let enemies = [];
// stuff
@Initialize
{
// stuff
}
@MainLoop
{
// stuff
if (we_should_spawn_a_shot)
{
let enemy=Obj_Create(OBJ_SHOT);
Obj_SetPosition(enemy,GetClipMinX+100,GetClipMinY+100);
Obj_SetSpeed(enemy,3);
Obj_SetAngle(enemy,90);
ObjShot_SetGraphic(enemy,RED01);
Obj_SetAutoDelete(enemy,true);
enemies = enemies ~ [enemy];
}
let i = 0;
while (i < length(enemies))
{
if (Obj_BeDeleted(enemies[i]))
{
enemies= erase(enemies, i);
i--;
}
else
{
let obj = enemies[i];
// Do object processing for the object identified by obj
if(Obj_GetY(obj)==200){
Obj_SetAngle(obj, 270);
}
}
i++;
}
}
(Disclaimer: I didn't actually test this code; I only wrote in the relevant parts. Given the rest of a script around it, it should work)
The important part here, in order to get each bullet to process correctly, is where it says
let obj = enemies[ i ];This pulls each object's ID from the array, so we can work with that individual object.
Also, another thing which is an issue in your code is the comparison itself:
if(Obj_GetY(obj)==200)I'm pretty certain Danmakufu uses floating point numbers for positions. Floating point numbers can be prone to error due to rounding and such, so it is possible that the Y position of the bullet never hits
exactly 200, but rather hits something like 199.999999 - in this case the
if will never trigger because it will pass right by 200.
In fact, with the values you've given, the Y coordinate will probably never hit 200 exactly. I believe
GetClipMinY returns the value 0, so you're starting your bullet at the Y coordinate of 100, moving straight downwards at 3 pixels per frame. If you do the math, the Y coordinate of the bullet is, per frame:
100, 103, 106, 109 ... 187, 190 193, 196,
199,
202At this rate, even if floating point error doesn't come into play you're still never going to hit 200 exactly.
There is a better way to handle this condition. Since your bullets start off moving downward, and reverse direction once they hit Y = 200 (to go upwards), you can simply change the
if to check if the Y position is
at least 200:
if(Obj_GetY(obj)>=200)With this, even if the bullet doesn't hit Y=200 exactly, it will still reverse direction.
Hopefully, this'll help you get going.
(PS - that array example in the Object Shot tutorial is meant more to give people a framework to throw their object shot processing code into, rather than as a tutorial on arrays themselves. Perhaps another tutorial is in order?)