lucid's Forum Posts

  • thx dmy, and yes, that is the solution i was planning, a "destroy and delete all instances of". with the option to replace the other instances with defaults so other array members wont have to have their indezes displaced..i will also add this for the other types of arrays as well.

  • <img src="http://dl.getdropbox.com/u/1013446/s/s.png">

    Let's learn.

    Even if you grabbed the cap file from the previous post, please redownload it. The events have been reordered to make the tutorial flow better. http://dl.getdropbox.com/u/1013446/s/objectarray3.cap

    try the cap first, and then let's look at the events

    <img src="http://dl.getdropbox.com/u/1013446/s/objectarray3cap/1.png">

    Ok, in the start of layout we are creating two object arrays.

    There are some extra considerations for object arrays we will go over briefly. Future updates will reduce or eliminate these issues, however, the main thing to understand is that for now, if you destroy an object, attempting to read from that object or alter the object through the reference after the object's destruction will invariably cause a crash. There are several features already implemented to help you avoid this that will be covered in this tutorial, and there are several updates planned that will make it difficult or impossible to crash, while maintaining the same power and flexibility.

    With object arrays there are some extra options to consider when creating a new array. If you double-click the " object array" actions you get this:

    <img src="http://dl.getdropbox.com/u/1013446/s/objectarray3cap/0.png">

    We name the array "thingstochase". This array will hold references to all the enemy sprites that's have been clicked and are targeted for attack. until next tutorial we ignore "within which super".

    object, for the type. For the default value we have the type of the object we want as the default. If there is more than one of that type picked, the first instance will be the default.

    The ot({"objecttype address"}) expression can be used any where objecttypes can be entered. This is not limited to 's', and this includes the dropdown boxes you use to pick types. You can right click on that parameter, and click "use expression", and that allows you to enter a type in quotation marks, or the ot({"objecttype address"}). There is an equivalent operation that returns the type of an object. This would be o({"object address"}).

    At the bottom there are two options specifically for object arrays.

    The first is "objecttype for default". Object variables only reference the object, they are not the objects themselves. You can have an array of ten, and have every one point to the same object. Any default values created will be multiple references to the same object if you leave ObjectType for Default as "notype". If you were to insert an object to the array at index 43, 0-42 will be filled with references to the single default object. There are certain situations where this might be the ideal solution. For instance, you are adding speed boosts to physics objects in an array. Each instance of the objecttype in the array would add to the total boost of that object.

    The default sprite is not destroyable using any of s's methods of object destruction. Commands issued to destroy the default are ignored. This is to prevent you from accidentally accessing the default after accidentally destroying it. Also, this allows you to freely delete objects from your array without any special provisions for the default object.

    While having multiple references to the same object is ideal sometimes, in other instances, when you insert an object at 43, you want 0-42 to be 43 different instance of a specific type. This is what ObjectType for Default is for. You specify a default type, of which an instance will be created each time an object is inserted to an array index outside the range of the array. So you would get 43 unique sprites of the default type. They are spawned on the layer specified in the last parameter. Even when using ObjectTypes for defaults, you still need a default object, which will be returned if an attempt is made to read from an object outside the range of the array. The default object can be something as simple as an invisible 1x1 dummy sprite, or the properties of default objects can be used as part of the logic, as is the case in this tutorial.

    {"thingstochase"} will be an array for the enemy targets.

    and {"drones"} will be an array for our drone missiles

    <img src="http://dl.getdropbox.com/u/1013446/s/objectarray3cap/5.PNG">

    the first part of the always event with sprite4 was just part of the code to make it look cool.

    Next we come to :

    <img src="http://dl.getdropbox.com/u/1013446/s/objectarray3cap/6.PNG">

    "On left click on blue" (blue is all the ships)

    Insert object blue to "end" of {"thingstochase"}

    so if a blue object is left clicked, add a reference to that object in {"thingtochase"}

    If the right mouse button is clicked, make the player ship spawn one of our drone missiles (the pink thing), and then add a reference to this new drone missile instance to the {"drones"} array

    Now we have unlimited access to the picking of these objects. Remember that you don't need to add objects at the end, they can be inserted and overwritten at any point in the array.

    The first subevent

    <img src="http://dl.getdropbox.com/u/1013446/s/objectarray3cap/2.png">

    is an Object Array 'for each' loop

    If you double click and take a look inside:

    <img src="http://dl.getdropbox.com/u/1013446/s/objectarray3cap/3.png">

    First we have the name of the loop, "killthem!". Then the address of the object array we are looping through.

    The third option is new.

    Picking method:

    <img src="http://dl.getdropbox.com/u/1013446/s/objectarray3cap/4.png">

    This decides what effect the object array loop has on picking

    • "Do Not Alter Picking" does not alter picking
    • "Pick Only Current Object", which is selected in this particular loop, picks only the object pointed to at the current index of the loop
    • "Toggle Current Pick" picks each object if it is not picked, and unpicks it if it is
    • "Add Object to Current Picking" adds the current object to the list of picked objects, instead of only picking the one object. The picking method option is present in other actions and conditions, but in the case of a loop, this makes the list of picked object continue to grow as the loop goes on
    • "Unpick Current Object" mostly self-explanatory. I may add an option for this in the future, but the way picking works, before any conditions are met, nothing is picked, so actions act on everything, but "unpicking" in this case does not remove the item from "everything". If any conditions have changed the picking of the object type, then this will work as expected.
    • "Pick All of Object Type" picks every object of the same type as the object at that index in the array

    Underneath this, you see "pick as"

    "Pick as", takes either "self", where an object is picked as it's own type, or the name of a family. If you put in a family name, the object is picked as a member of the specified family. This is useful if you need to act on an array that contains several different object types. This also enables you to use non 's' actions, conditions, and expressions to refer to more than one specific object of the same type in an array. This is essentially the "family trick".

    For those unfamiliar with the "family trick". Here's an example of when this is useful.

    Let's say "Sprite13" is a member of the family "red", and a specific "Sprite13" is picked. you want to check if this instance of Sprite13 has a collision only with another Sprite13. And you want to do something different to the originally picked Sprite13, and the one it collided with. If you were to just check for collision with Sprite13, there would be no way of telling the first Sprite13 to go the left, and the one it collided with to go right. But if we check for collision with "red" (of which Sprite13 is the only family member), then we can do actions to either Sprite13 or "red".

    We are picking each object one by one in the object array "drones".

    The drones have the bullet behavior on, and we are telling them to turn towards S.x({"thingstochase",S.li("killthem!")}),S.y({"thingstochase",S.li("killthem!")})

    This is much simpler than it looks

    S.x is an expression to retrieve the x position of an object in an object array.

    {"thingstochase",S.li("killthem!")}

    is simply an object address

    S.li("killthem!") is the loopindex for for the "killthem!" loop.

    <img src="http://dl.getdropbox.com/u/1013446/s/objectarray3cap/2.png">

    "killthem!" is looping through the drone missiles.

    The first time through the loop, the first drone missile will get picked, and it will go for the first target in line.

    if there is more than one missile, the second missile would go to the second target.

    <img src="http://dl.getdropbox.com/u/1013446/s/objectarray3cap/arrays.gif">

    The next action is to pick the {"thingstochase"} object at the same loopindex as "blue", since we're not sure what it will be.

    <img src="http://dl.getdropbox.com/u/1013446/s/objectarray3cap/8.png">

    here, on collision between sprite and "blue" (the only "blue" picked right now is the one on the current loopindex, so this collision check will be only between the drone and it's current target)

    if "blue" is of type "sprite", which is the player ship. This condition simply checks if an object is of a certain type, you can give the name of a picked instance, or you can give an object address.

    if the blue that the drone collided with is the player sprite type

    <img src="http://dl.getdropbox.com/u/1013446/s/objectarray3cap/9.png">

    delete the drone sprite at the current loopindex. When the drones return to the player ship, they're supposed to disappear. when deleting an object reference from an object array, or several references from an object array, you have the option to "destroy all objects". If this is the only way you destroy objects that are in an array, you're safe from accessing a destroyed object accidentally. I will also be adding an option to destroy all instances within the array of the same object. That will make the system truly foolproof. Back to the cap, now we've gotten rid of the "drones" object reference and the drone sprite itself.

    <img src="http://dl.getdropbox.com/u/1013446/s/objectarray3cap/10.png">

    if the "blue" that the drone missile collided with isn't the players ship,

    Delete the current loopindex object reference in "thingstochase", the enemy ship, and destroy the ship object itself

    Next we delete the current drone object reference, but this time we don't destroy the object, it is still picked, and we add it to the end of the array.

    the reason this is done, is because if not all the drones would change targets when one of the targets was deleted:

    <img src="http://dl.getdropbox.com/u/1013446/s/objectarray3cap/arrays.gif">

    imagine the top enemy ship being deleted, and the rest moving up to fill in the gap. then the second drone missile would be aligned with a different target.

    Because the mothership is the default, when all enemy ships are destroyed, the drone's current targets are the mothership. because of the way we are looping through both arrays with a single array index, we know missiles will not pursue one another's targets. This is just one type of logic. There are an infinite number of ways you can use object arrays.

    The next tutorial(s) will introduce supers, and we will be done with all the basic tutorials.

    Thanks to everyone who's using s and reading the tuts

  • yeah, gml, is game makers scripting

    as of now python doesn't work with the picking system, picking being central to making construct awesome. But scripting is unnecessary, which is also what makes construct awesome.

    making a turn based game should be no trouble, I recommend the ghost shooter and platform school tutorials. learn the basics. try your turnbased ideas a little, and then ask more specific questions if you run into trouble

    welcome to scirra

  • cool, thanks link, i didnt know about pinfo.ill have to have a look into that, especially for the new plugin

  • It dose not work.

    It just delete the first numerical index now,

    I need it to delete the index with the smallest value.

    I need for example:

    array {"1"}

    its not working because you put quotation marks around the number

    use the curly braces, like youb did, but not {"1"}

    it should just be {1,3}, and only if your specifying a range, if its just one index you want to erase at a time, no curly braces, no "", just the number

  • i dont know if this is a mistake copypasting but you have an ADDPARAM(PARAM_ after your first param...since these are macros and not functions, it might still be compiling, but not ina any sensicalw way..as for debugging. run a exe preview, and goto vs and debugging attach to process, and attach it to the temp.exe....you have to choose the debugging exe when building for it to work

  • not possible to get or set z-elevation through another plugin. however, you do have z-order options, and you can set eh z-elevation easily with a "for each letter" loop

  • Is there and way to delete a container minimum and maximum value not just the value at the end of the container.

    yes, "end" is the last element in the array, you can also use any numerical index,0 being the firfst in the array. and i havent tested it much yet, but you can also specify a range of values as (min, max), such as (1,"end"), or (2,3), howver you must use the curly brackets, but my phone doesnt let me type those

  • SPAM REMOVED

    I hear spam a good way to get started, too

  • yeah, you only needed a few files from the common folder, but that's probably easier

    happy plugging

  • yeah, links right

    i was thinking of the 360-0 gap, when i did the adding thing, but thats at 3oclock not 12 oclock

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • dont give up...that art is beautiful.

    ok, the equation you need is as follows

    get the angle of absolute red, and get the angle of absolute blue

    to get the arrow to point to the correct level of health:

    (lerp(0,(blueAngle-redAngle),currenthealth/100))+redAngle

  • thank you, alspal, i edited it after you posted your first post, did you see I responded to your question about the crashed cap?

    <img src="http://dl.getdropbox.com/u/1013446/s/s.png">

    things are about start coming together, the next tutorial I have planned is on object arrays, as opposed to objecttype arrays. This post is not the full tutorial. It is a description of the problem we are going to solve with object arrays, and the example cap to do so. You may be able to figure most or all of it even without the tutorial.

    so here's the problem.

    create a weapon for an overhead shooter. You can left click on enemy ships to make them targets. Click the right mouse button to fire out drone missiles. The drone missiles should attack the targets one by one in the order you clicked them. if you fire more than one missile at a time, the missiles should take over the next target in line. No two missiles should ever attack the same target at the same time. After all targets are either destroyed, or currently being pursued by another drone missile, the drone missile should return to the mothership.

    This can be accomplished in relatively few events, using s.

    http://dl.getdropbox.com/u/1013446/s/objectarray3.cap

    there's the cap, tutorial coming soon

    have fun

    a note on crashes: if you click the same target twice you can make it crash. These are not random stability problems, I understand where the crash is coming from. I am working on ideal solution that will both maintain the power s and usability . The default system is the solution to the problem of trying to access values outside the array. This used to cause a crash, but I didn't want to return a meaningless value either. It turned out to be useful in another ways. The following problems also require solutions that both prevent the crash, but also make it obvious where something is going wrong, instead of just being a silent bug in your code. In the meantime, there are a few things that make s crash that can be avoided if you are aware of them. 1. typos. misspelling a name, forgetting an element to an address, or doing "this" instead of {"this"} 2. destroying an object, and then trying to do something with an object variable that pointed to it. 3. destroying an array, and then trying to access it. please report any other crashes also, everywhere you're expected to type an array address should begin like this {""} so the brackets are already there when you start, this goes the same for expressions. Please let me know if you discover them missing anywhere. Also, anywhere you can type in an object address, you should be able to use the name "in quotes" of any picked object. Please let me know if you discover anywhere this does not work. thanks everyone who's helping me test this.

  • thanks for this.

    I get a runtime error when clicking in the last .cap and it closes?

    sorry, change the loopname on createtext to numloop instead of nummy

    I changed the names at the last minute, and forgot to change it there...also, you can just redownload the cap at the same link, I fixed it

    <img src="http://dl.getdropbox.com/u/1013446/s/s.png">

    ok, for this tutorial you will need to redownload the plugin, if you downloaded it before this tutorial was up.

    This is a simple objecttype tutorial, to introduce objecttype arrays.

    http://dl.getdropbox.com/u/1013446/s/objecttypetutorial.cap

    in this little game thing, you have a default green thing as your attack (space bar)

    as you pick up items they are put in a queue, and each time you press space you use the first item in the queue, when you run out of special items, you fire your default again.

    at the beginning you see I deactivated bullet movement...this was just so the objects would sit there until you picked them up.

    on collision with blue I inserted tt("blue") into the array

    tt stands for true type, you can of course choose a normal type, or a family to be added to the array. In this case, we don't want the type "blue" inserted into the array, we want the "true type" of the object, not the family type. this expression only works if there is an actual object, because of course there is no true type for the family itself.

    so we insert the type at the "end"

    and destroy the "blue" object

    on "space bar" pressed

    spawn the type at {"types"} (which is {"types",0})

    and delete that entry in "types"

    try out the cap, and try to understand the events.

    now we are going to change it a little bit

    we want to make lightning the new basic weapon, if we pick that up.

    http://dl.getdropbox.com/u/1013446/s/objecttypetutorial2.cap

    on collision with "blue"

    we use a condition from s

    "is of object type"

    we check if "blue" is of the lightning type. in this condition, you can also type in an arrayaddress for an object type or even the array address of an object using the o expression o({"objectarrayaddress"})

    if it is of lightning type, we use the "new default value for array" action to make lightning the new default, and then we destroy the object we picked up

    else, if it is not lightning type, we add it to the array the same as in the previous version

    The next topic will be object arrays, then super arrays. then we will start to see full examples of complex projects, like inventory systems, and level editors, and we will see how s works to make these types of projects simple, and with few events.

  • you should be able to use set and get controlstate. make sure you have the latest version of the sdk from this board. if it does not have those functions, reply back for instructions on how to update your sdk