David's Forum Posts

  • Another (and faster) way is to instead of using the for loop and the system compare, is to use the compare condition in the enemy object. This is just like the system compare, except the comparison is evaluated for each instance of enemy, picking the ones that meet the equation. So then you would use:

    -> Distance(.X,.Y,player.X,player.Y) < attackdistance

    == ATTACK!

  • Okay a quick thing to know about functions. Any variable that is declared within a function can only be used in the function. eg:

    <img src="http://dl.dropbox.com/u/939828/Tutorial/Script5.PNG">

    This script wont work and you'll get an error about an undeclared variable. This is due to a common thing in programming languages called 'variable scope'.

    Well this is all I can be bothered writing for now

  • Lets now take a look at how Construct handles multiple blocks of script.

    Lets say we create two scripts, one that sets a variable, and one that adds that variable to our ListBox:

    <img src="http://dl.dropbox.com/u/939828/Tutorial/Script3.PNG">

    awesome = "Scirra"[/code:3tbzidv8]
    [code:3tbzidv8]ListBox.Add( awesome )[/code:3tbzidv8]
    Right now what we'll notice happens is that the List box adds the line 'Scirra' when you press the button. This might seem pretty obvious, but for clarification, variables declared inside a script block are 'global' in that they are available to other scripts as well. This doesn't just include variables, it also includes classes and functions.
    
    Okay lets have a look at how to declare a function!
    
    <img src="http://dl.dropbox.com/u/939828/Tutorial/Script4.PNG">
    
    [code:3tbzidv8]def MyFunction(param):
    	return param + " without my pants"[/code:3tbzidv8]
    Basically what we have done is declared a function 'MyFunction' which takes a single parameter called 'param'. Note that we dont declare the type of variable the function takes. It then returns the combination of whatever is in 'param' and the string " without my pants"
    
    [code:3tbzidv8]ListBox.Add( MyFunction("scirra") )[/code:3tbzidv8]
    Here we add a line to the list box. Instead of adding "scirra" or a variable, we call the function MyFunction("scirra"), telling python that we want to evalulate 'MyFunction' with param = "scirra". The result is it adds "scirra without my pants" to the list box
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Right so we've had a quick look at how to get something up and running in python. Now lets take a close look at the python language itself.

    awesome = 10[/code:3o8cahs5]
    This declares the variable 'awesome' as 10
    
    [code:3o8cahs5]face = "hillarious"[/code:3o8cahs5]
    This declares the variable 'face' as a string 'hillarious'
    
    [code:3o8cahs5]
    variable = 5
    if variable == 5:
    	Text.text = "cool"
    [/code:3o8cahs5]
    If you were to run this code, you would need to put a text object on the layout called 'Text'. But basically, if variable == 5 means:
    
    [i]If the variable is equal to 5, run the code which is indented below'[/i]
    
    Important things to notice is the indentation, the fact each 'instruction' is on a separate line, and that the if statement has a : at the end... also take note that python uses two equal signs for 'is equal to' like java and C++.
    
    [code:3o8cahs5]for n in [1,2,3,4]:
    	ListBox.Add(n)[/code:3o8cahs5]
    To make this code work, you need to have a list box on the screen. Basically, for loops always loop over something. In C++ you might be familiar with writing: [i]for( int x = 0; x < 10; x++)[/i]...but python instead loops over all the elements in a set.
    
    If you need to loop all the numbers from 0 to 100, its a waste of time to write [0,1,2,3,4,5.... so theres a handy function to remember - range:
    
    [code:3o8cahs5]for n in range(0,10,2):
    	ListBox.Add(n)[/code:3o8cahs5]
    
    This will output 0, 2, 4, 6, 8 ... but not 10...so in C++ its the equivilent of writing:
    
    [i]for (int n = 0; n < 10; n+= 2)[/i]
    
    However, the python version is a bit shorter and probably easier to read! However it does take a bit of getting used to.
  • Okay so first off what is python:

    'Python is a general-purpose high-level programming language. Its design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive. Its use of indentation for block delimiters is unusual among popular programming languages.' - wikipedia

    Okay so basically, its a programming language, which means that you gotta type stuff.

    First, insert a Sprite onto the screen. Then switch to the event sheet editor. To insert a 'script' block, right click and select 'insert script'

    <img src="http://dl.dropbox.com/u/939828/Tutorial/Script2.PNG">

    Lets start with a really simple script

    <img src="http://dl.dropbox.com/u/939828/Tutorial/Script.PNG">

    Sprite.X += 1[/code:2dnrrrmr]
    
    When you run it, that sprite will move to the right 1 pixel per frame. Basically this script block of python is run each frame, just like events are. In fact, you can place a python script anywhere in the event sheet just like a regular event (ie. You can have a python script as a sub event)
    
    Switch back to the layout editor, hold control and make a second instance of 'Sprite'. In fact, make a couple (press enter as you drag instead of constantly dragging and dropping) and now run the application.
    
    You will notice only the first instance moves, none of the others do.
    
    Python only evaluates one instance (in this case, the first).
    
    If you want to move other instances, you need to refer to them in an array notation. Eg:
    
    [code:2dnrrrmr]Sprite[0].X += 1;
    Sprite[1].X += 1;[/code:2dnrrrmr]
    
    Or...and this is a better way...take advantage of python for loop:
    
    [code:2dnrrrmr]for s in Sprite:
    	s.X += 1[/code:2dnrrrmr]
    
    This means it will loop each instance of Sprite, and move it along the x axis by 1 unit per frame.
  • Cool. So basically instead of splitting an image by a grid (eg. 32x32 pixels) it splits the image by 'gaps'. So when you write 'ABCDEF' etc... each letter has a gap between it and so it crops and makes an image out of it? Would it be useful if I added that functionality into the import image dialog. A 'split by gap' button?

  • Its not very obvious, but if you right click on a parameter you can select 'use expression'.

  • Some day I'll make a game where everything is made up of credits. Like you play a giant C shaped character jumping over platforms which are all logos for stuff like photoshop, Construct, Windows, and various other tools used to make the game

  • If it ended with the humans winning, around the time that the giant tree was destroyed...then yeah it would have been a 'deeper' ending that leaves everyone questioning imperialism etc...but by having a happy ending it still leaves people questioning but not the same degree...kinda amazing to think what power the script writers have on a big movie like that...so many people watching it....

  • So long as construct NEVER forces a logo or any kind of branding onto anything someone has made with the software, then as per my original vote. I'm more than happy to let everyone know what I used to make it.

    Haha nice...so if we make it manditory to include a logo/brand for using our product for free that we have invested hundreds...or maybe thousands of hours into, you wont be happy Sorry I just found that kinda funny, but at the same time I know what you mean. Its like donations where you're forced to pay at least $1 for the product...doesn't feel like much of a donation if its manditory. But dont worry, we dont plan on adding a splash screen or whatever. They are annoying.

  • seriously there are stupid people out there. someone rated construct 0 out of 5 with the comment 'wheres the source?!' ... I love how the entire project was therefore worth NOTHING because the guy was too much of a moron to know what SVN/CSS were and not even consider that maybe he had overlooked something. Also there are lots of commercial open source projects out there, so free emphasises it... although your right its kinda like putting 'emergency ambulance' ... you'd think 'ambulance' would be enough

  • win1

  • <img src="http://dl.dropbox.com/u/939828/construct%20powered.png">

    heh

  • You do not have permission to view this post

  • haha 'Expression Stacker' was just a name for it because I imagined people dragging and dropping expression bits and pieces onto each other like a stack...or a pile...

    Anyway I dont think it's really something that would be useful. Its good practise to learn how to type expressions. I added syntax highlighting and bracket matching to the expression editor anyways.

    Here was a final design I came up with

    <img src="http://dl.dropbox.com/u/939828/stack3.PNG">

    Basically, a 'block' could be setup so the text was in the middle...so the Multiply looks like a proper multiply...and secondly the parameters dont have text for them (Multiply doesn't need text with A, B) then the stack above is lowered.

    The only remaining problem with the stack is if you do something like:

    5 + 3*3 + 2 you end up with 3*3 as one stack, and 5 + (3*3) as the stack below, then (5+(3*3))+2 as the stack below that.