David's Recent Forum Activity

  • A late Christmas present Great job!

  • Ah it was actually caused by attributes! fixed now

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Correct. There are no triggered conditions at the moment. You need to use construct to make a trigger, and then have a script as a sub event.

  • 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
  • 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....

David's avatar

David

Member since 21 May, 2007

None one is following David yet!

Trophy Case

David has no trophies yet!

How to earn trophies