A few small questions

For questions about using Classic.

Post » Sat Sep 25, 2010 12:17 pm

I have a couple of questions which I haven't been able to figure out for the past 2-4 hours. The first deals with .ini files, and more importantly, how to incorporate them. The second deals with changing objects, simply put. Lastly, the third is about trying to randomly select a number, etc for some simple "if" statement equivalent.

Because it makes more sense in my head, I'll do this backwards, and start with three. I have a bit of experience working with Python, and could easily do this if I were just doing python. But, since I don't know how Python and Construct work together, despite this nifty guide.

Could someone show me how I could go about generating a number between 0 and 2 (ie 0 and 1, if I remember correctly), and assigning this to a variable which Construct would allow me to use in another event? What I want it to ultimately do, is determine whether Team 1 or Team 2 gets the ball.

Which leads nicely to the second question. How do I go about changing an AI object to the Player's control, so that the object can then be moved via keyboard? Do I simply delete one object and spawn another in its place, or is there a better way to do it? My only concern here is that if the object is tilted 90 degrees and then I do the spawn/destroy method, the object will spawn in default position. Needless to say, this looks jerky. I can live with it, but if there's a better way, I'll take it.

My first question goes into how I can use a .ini file to import character data, and then use it within Construct. Things like using their assigned Speed value to dictate how fast the object moves, or using their Shooting skill to do a simple calculation against the goalies Catching skill. Furthermore, is it possible to overwrite a single value in an already present .ini, without mucking around with the entire thing? As in, upgrading Joe Smiths level/stats, without screwing up John Doe and Jane Baker.


The Wiki really helped me understand the What, but now I'm just stuck on the How, I'm afraid. Thanks in advance, and goodnight. Maybe I'll sleep before the sun comes up. Blasted Construct, eating away my night!
B
1
G
2
Posts: 1
Reputation: 627

Post » Sat Sep 25, 2010 1:51 pm

[quote="Davdak":36ea2j31]Could someone show me how I could go about generating a number between 0 and 2 (ie 0 and 1, if I remember correctly), and assigning this to a variable which Construct would allow me to use in another event?[/quote:36ea2j31]
All you have to do is set the variable (either a global or an object variable) to random(2). random(a) returns 0 to a-1, so in this case it will choose 0 or 1. If you pass a whole number it will return only whole numbers. If the number has a decimal it will return a random float from 0 to a-1.

[quote="Davdak":36ea2j31]Which leads nicely to the second question. How do I go about changing an AI object to the Player's control, so that the object can then be moved via keyboard? Do I simply delete one object and spawn another in its place, or is there a better way to do it? My only concern here is that if the object is tilted 90 degrees and then I do the spawn/destroy method, the object will spawn in default position. Needless to say, this looks jerky. I can live with it, but if there's a better way, I'll take it. [/quote:36ea2j31]

It doesn't look jerky if you set it up well. You can modify object properties when they are spawned, so setting the angle to the AI angle on the frame it spawns will look like a flawless transition. You could also set up a variable called playercontrolled to make it so the ai becomes player controlled when the value is 1 instead of destroying it and spawning a player object. It's your call.

For ini files, there are write value actions, and read value expressions. The write actions just write a value to an item in a group. The ini only writes or reads where you tell it to write to. So for instance you can have a skill value for your goalie whose value is set to the ini's value "catchskill" in group "goalie". At the start of the game you could set all the players skill values to the corresponding ini values. You could even have different ini files for each team, so you can save and train teams or whatever.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests