Silent Cacophony's Recent Forum Activity

  • Yeah, Python has many ways that one can implement an array, or something similar.

    In the example above, I built a single-dimensional list to match the single-dimensional array in Construct. The list could have been used instead of the array just as well, but Construct's array object has it's own uses, too.

    Python lists can also simulate multi-dimensional arrays by using lists of lists, like so:

    l = [[1,2,3], [4,5,6], [7,8,9]][/code:3cf635dg]
    
    ... where l[1][1] would reference the value 5. Initializing a multi-dimensional list can seem a bit odd compared to doing the same with an array, because they work a bit differently. Here's an example that builds a 2-d list of 1s, x by y. This uses a handy list comprehension, which is basically shorthand for a normal loop, and operator overloading with the '[1] * x' to build the inner lists of x number of 1s.
    
    [code:3cf635dg]l = [[1] * x for j in range(y)][/code:3cf635dg]
    
    If x = 4 and y = 6, the above results in l containing:
    
    [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]
    
    There are also the 'array' module and 'NumPy' extension that can be imported for real arrays, and dictionaries with tuples for keys can even be used as a sort of array.
  • namre, it sounds like you may be using a version of Construct before 0.99.84, which is the earliest version that Python works in. You may need to install the latest (unstable) version from here: http://www.scirra.com/forum/viewtopic.php?f=2&t=6488.

    Anyway, I think that sharing Python classes, functions and code snippets is a great idea. Although, the Python integration in Construct is not yet fully implemented, and could use some more general polish, some things can still be done quite nicely with Python.

    For instance, on the topic of sorting, Python has a very nice built-in sort using the Timsort algorithm. But, probably one of the most likely things that someone might want to sort is the Array object, and it doesn't seem to be readable from Python. It's not too difficult the make a Construct function that takes care of the bits that don't yet work in Python, and also add the script in there, but it's not so convenient as just a function or class definition in Python. It can, however, be called from Construct or Python, once made.

    For example, I made a .cap that will sort an Array of 3,000 random numbers between 0 and 30,000. If I could read the Array from Python, a simple Python function could be made that could accept a reference to the Array object to be sorted. Instead, I had to use a Construct function hard-coded for a specific Array object. Not yet an ideal situation.

    I may as well include the .cap here, though.

    http://dl.dropbox.com/u/5868916/SortExample.cap

    The function copies the Array to a python list, sorts the list, and copies the list back to the Array. Seems fairly quick despite the overhead, averaging about 0.034 seconds per 1,000 entries on my machine.

  • Hi, I was interested in this problem, so I took a look at it.

    That's a nice way to set up a variable number of choices in a selection menu, lucid.

    Anyway, I made a couple of changes to make it work, lildragn. The main change is just what happens when you hit enter:

    + MouseKeyboard: On key Enter pressed
    + Blue: Pick by Blue.Value('ID') Equal to global('screenSelect')
    -> System: Go to layout Blue.Value('choiceName') with transition "None" lasting 0 MS[/code:2pk30t3i]
    
    This is one way to do it. Note that here it's telling Construct to go to the layout with the same name as the contents of the string in the variable 'choiceName'. As lucid mentioned, if your target layouts were named as "Layout 1", etc., you could very well use [i]"Layout " & Blue.Value('ID')[/i] instead of [i]Blue.Value('choiceName')[/i], or some other scheme entirely. The picking of the menu item was the main thing to accomplish there, so you can get the ID or choiceName for it.
    
    The other changes that I made were just things that I would have done differently, to the same result, though. Here is the modified .cap:
    
    [url]http://dl.dropbox.com/u/5868916/prototype_brawler3%282%29.cap[/url]
    
    Good luck.
  • Also, the wiki has a couple of examples of using the two different operators (+ and &), under 'Building strings with &' on this page:

    http://sourceforge.net/apps/mediawiki/construct/index.php?title=Expressions

    There are a few handy bits of info on that page.

  • This is brilliant. It will be a great reference if I ever get around to making a metroidvania game, which I would love to do.

    Thanks for contributing it, UberLou.

  • Sure. Since I decided to learn Python a few months ago, I've found my favorite programming language, ever. I hadn't done any programming for 10-15 years before that, and missed it. I used to use C, Pascal, ARexx, BASIC, and Assembly way back then. I was probably most productive with ARexx, which is somewhat similar to Python.

    Anyway, Python is what finally made object-oriented programming 'click' for me. Even though some feel that it's not fully adherent to the OOP concepts, I think it's quite fine. And it's fine for functional and procedural programming as well.

    So far, I've done a few utility scripts for my own use. Things like batch processing of files and other such occasional tasks. I've also made a couple of quick scripts for work, to process CNC programs from a networked computer to several CNC machining centers, since the existing antiquated software sucks. I plan to make a nice GUI program for that soon.

    I've started work on a Roguelike game, which I plan to implement in Construct, and probably a text-based, pure python version eventually. These types of games are a great argument for using Python. They lend themselves well to OOP methodology, and Python can handle all of the data crunching and most of the logic, while Construct can do the nifty display and behaviors. While I have gotten used to event-based programming in Construct, I am way more comfortable with code when it comes to lots of data and/or logic.

    I have already thought of quite a few more things that I will eventually make in Python. A checkbook accounting program that I will actually USE, Some more utilities for my own quirky computer use, and possibly using it to glue a couple of applications together, to name a few. Hopefully I can still make progress on and finish some games with Construct, too. Seems like there is never enough time.

  • Sounds like it will be quite complex, indeed. While I wouldn't say that Construct wouldn't be able to handle the data storage and manipulation with it's native data structures, I would suggest thinking about using lucid's 's' plugin, or Python Classes, to deal with all of the data needed for such a game.

    I have not tried the 's' plugin. It sounds like it would fit the ticket nicely, though. Since I am quite comfortable with Python, though, I would definitely use classes for each of the components involved. Object-oriented strategy would work well for something like this. At least, one can use Python Classes as a sort of c-like 'struct' in which one can have structured groups of different types of data with meaningful names. These are also capable of pointing to each other, thus 'linking' to each other. It can be a bit tricky interfacing Python code with Construct's events, but it's not too bad...

    I'm not sure of your sectioning of the game universe, but off of the top of my head, I can see I'd want some basic data structures like so:

    Ship:

    • 'Health'
    • Speed
    • Armor
    • Class of ship
    • Armaments (list)
    • fuel capacity
    • current fuel
    • cargo capacity
    • current cargo (list)
    • current location

    Station/Planet:

    • sector located in (link to sector)
    • Type of economy
    • population
    • crime level
    • needed goods (list)
    • surplus goods (list)

    ... etc

    Sector:

    • bordering sectors (list of links to other sectors)
    • ships in sector (list of links to ships)

    ... etc

    ... and much more data than that, depending upon the complexity desired. The trick is to make it as simple as possible in the hidden inner workings of the game, while making it seem complex/realistic to the player. It could be as simple as having an array/list of ships that you loop through every tick of the game, having them make decisions based upon semi-random choices.

  • Hi. This is a common type of scenario that you may run into when developing a game. That is, dealing with discrete states for some aspect of the game. In this case, you'd need to set some sort of 'button pressed once' state when the button has been pressed once, and clear that state if the button is pressed again (as well as taking the desired action), or if the other button is pressed instead.

    As has been mentioned, variables are generally used for such a thing. If this is not going to be needed in other layouts, then a global variable would not be needed. In such a case, a private variable could be added to both sprite objects to keep track of the current state of each. However, in your example, the Shake behavior can be used as a simpler solution by using the Is Shaking condition that comes with it. I made a simple example of how I would implement it, here (v0.99.84):

    http://dl.dropbox.com/u/5868916/Choices.cap

    Here's a slightly abbreviated text version of the main events:

    + MouseKeyboard: On key 1 pressed
    	+ Sprite1: Is shaking
    		-> Text: Set text to " Sprite1"
    		-> Sprite1: Stop shaking
    	+ System: Else
    		-> Sprite1: Start shaking for -1 ms, with intensity 2
    		-> Sprite2: Stop shaking
    + MouseKeyboard: On key 2 pressed
    	+ Sprite2: Is shaking
    		-> Text: Set text to " Sprite2"
    		-> Sprite2: Stop shaking
    	+ System: Else
    		-> Sprite2: Start shaking for -1 ms, with intensity 2
    		-> Sprite1: Stop shaking[/code:zu6vif0g]
    
    Note a few things about how I set up the events:
    [ul]
    	[li]I used [i]On key pressed[/i] instead of [i]On key down[/i]. If I had used [i]On key down[/i], I would have had to add [i]System: Trigger once while true[/i] to that condition to keep it from toggling for every tick that the key is down. [i]On key pressed[/i] will only be true for the duration of the tick that is is detected in.[/li]
    	[li]The state checks are added as sub-events of the triggering action (the key press in this case.) Logically, this is less error prone than trying to make conditions without sub-vents, which can often lead to the undesired result of both states being true in succession, in the same tick, instead of just one.[/li]
    	[li]I used the [i]System: Else[/i] condition instead of an inverted condition: [i](NOT) Is Shaking[/i]. Else is good for checking between two states, as only one will ever be executed in one tick. If you use an inverted version of the first check instead, you can run into the problem of both being true, because the first condition toggles the state, and thus the second is now true because of that...[/li]
    [/ul]
    Anyway, if a variable were used for each choice instead of the Shake behavior, then you'd just need to set it to zero initially, then set it to 1 wherever you had 'Start shaking', and zero wherever you had 'Stop shaking'. Then, replace the 'Is shaking' condition with a check for the variable being equal to 1. Same concept, different method.
    
    I hope this helps.  I write this as much for others who may read this, having a similar problem. I see this type of problem often.
  • Hi. The CommonDialog object can do that. It allows file open & save dialogs, as well as directory and color dialogs.

    Here's a .cap (v0.99.84) with a simple demonstration of an open dialog:

    http://dl.dropbox.com/u/5868916/FileDialog.cap

    Note that the filter does not need to be set, and if you want to start in a particular directory, you can set that in the 'Set initial file' action, and optionally include a default file name in that string as well.

  • Hello.

    Game AI is one of the most difficult aspects of game programming. That's one reason why many games do not feature single player modes.

    It's difficult to say what would work for your needs, but 'custom movement' behavior with conditions dictating what the movement will be based upon what the player does would be a common scenario. There are generally no 'cookie-cutter' solutions to game AI.

    Construct also has 'Line of Sight' and 'RTS' behaviors that can be of great help in this area. RTS seems to be a 'shortest path to...' algorithm, and can be one way to implement chasing.

    Here are a couple of my Google searches that seemed to have some promising links:

    game ai programming

    shortest path algorithm

  • It's a tricky area... what do you think should happen? Do you think the current system (capped at once per tick) is OK?

    I can't really think of any good way for Construct to try and handle such a situation, other than how it does now. Since it really depends upon what one is doing at each interval, I don't think that there can be a catch-all solution.

    I would implement a variation of TimeDelta, as a function, which would report the time elapsed since the last call. Like so:

    + Function: On function "TimePeriodDelta"
    	+ System: Is global variable 'previousTime' Different to 0
    		-> System: Set global variable 'currentTime' to Timer
    		-> Function: Set return value to (global('currentTime') - global('previousTime')) / Function.Param(1)
    		-> System: Set global variable 'previousTime' to global('currentTime')
    	+ System: Else
    		-> System: Set global variable 'previousTime' to Timer
    		-> Function: Set return value to 0[/code:ypm3073b]
    
    This uses two globals, though it would also be good enough without 'currentTime', and accessing the Timer twice instead of once. Anyway, the first time it's called, it returns zero and starts counting time, then every call after will return the difference since last call. It takes one parameter, which the difference in milliseconds is divided by. Pass it the value 1 and it will return milliseconds, or pass it the same interval as your 'every ... milliseconds' condition, and the desired result would be one.
    
    For instance, for a '5 damage per 50ms' event, I pass the function 50, using it in expression form as a multiplier for the desired damage. Much like the TimeDelta.
    
    [code:ypm3073b]+ System: Every 50 milliseconds
    -> System: Subtract 5 * Function.TimePeriodDelta(50) from global variable 'Health'[/code:ypm3073b]
    
    I think a built-in such as this could be useful, but it's not difficult to implement anyway.
    
    I made a simple .cap to test this, which simply appends each result into an EditBox. I did get some odd intervals with low fixed frame rates.
    
    v0.99.84: [url]http://dl.dropbox.com/u/5868916/TimePeriodDelta.cap[/url]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There are a couple of other things I can add about this.

    As tulamide mentioned, Construct warns about the resolution of the every x milliseconds condition. However, it's generally not even good to 10ms resolution under the default settings. Under the application settings, "Framerate Mode" is set by default to "V-Synced", which effectively limits the resolution to 1/60 (or 16.667 ms) on my computer. It lags on mine until I set the increment to 17 or more.

    It's actually close to keeping up with the 1ms increment if I change the framerate mode to "Unlimited", where I get a framerate of around 2800. In practice, I've never felt the need to go below 50ms for any such condition, myself.

    Also, I've found it to be a good practice to not rely on exact equality checks for counters such as what you use here. You would notice that it breaks if 1000 is not a multiple of the increment value (as with 17.) I would usually use:

    + System: Is global variable 'MillisecondsB' Greater or equal 1000

    .

Silent Cacophony's avatar

Silent Cacophony

Member since 11 Mar, 2010

None one is following Silent Cacophony yet!

Trophy Case

  • 14-Year Club

Progress

14/44
How to earn trophies