farflamex's Recent Forum Activity

  • Yeah that's true, thanks for the explanation. If JSON is better, I'd rather just stick with it (I've grown very patient with old age) until I'm comfortable with it. All new languages/concepts are difficult at first anyway.

    Certainly I'd never need a pipe in any normal circumstance, so I don't see that being a problem.

    Wow, I've been using C2 for years and for some reason, I'd never noticed that you can mix types in an array, so that does help make JSON more appealing. I was thinking I'd have to send the strings and integers in 2 seperate arrays, but apparently not.

    This is almost tempting me to KEEP everything in an array during my C2 processing, but I absolutely hate arrays nowadays (used to swear by them until I became comfortable with objects). My old program (written in 1991) is all arrays and it's very difficult trying to work out what's happening when you read Rating(2,21) etc, it just makes no sense. So I always parse everything into an object when receiving in C2, then load it into an array to send it back to PHP, then split it again using your code and save it. Does sound long-winded when I could just keep it all in the array all of the time. But arrays are so hard to read and bug-ridden, I don't like that idea at all.

    Plus, when returning the data to PHP, I don't intend to send all of the data anyway, only selected bits (i.e the bits that have changed). So I'm effectively creating a small temporary custom-array, just to post it as my JSON string. That seems sensible instead of constantly sending the whole object back and forth when only a single value might have changed, though it also means more PHP scripts. Hmmm, lots to think about, but for now I'll stick with the JSON code until I understand it better (actually I understand the JSON part now, just the PHP is still confusing me).

  • Ok that's cool and I thought perhaps that was the reason. As far as sharing it, never going to happen as this game is my business and is run/operated entirely by me. I suppose it's feasible that some time in the future I may be dead and somebody else may wish to run the game for me, but even then, it's not like my code is that hard to understand (I do comment for example, only for my own sake though).

    In terms of ease and bugs, I personally find my method better since I need to move my objects into an array first anyway. And for me, it's easier to understand, although at some point, obviously I'll start to understand the PHP code better, but right now it's all completely unreadable to me and I'm relying on help to code even small code such as the bits above. Though of course, I need to use PHP so the more code I play around with, the better.

    Plus surely you do need to parse the JSON array at the PHP end? That's what the code above is for that Troublesum has written out for me. Is there a more straightforward way to get the C2 array into a PHP array?

  • I know what you mean, but I would say give C2 a try. It's really incredibly powerful and amazingly easy to use... apart from a few things which occasionally break my brain, but that's true in any language. It also has a good community and constant updates, although that's true of Unity of course. The problem, like anything, would be the learning curve. It did take me some time to get my head around C2 but I'm glad I did, and while it's not perfect, it's closer to perfect than anything else I've seen.

    I suppose much depends on what you're trying to do too. C2 isn't for 3D games so if you're planning any 3D, I assume Unity is the way to go.

  • troublesum, just wondering if you know if there's a good reason not to create my own strings and parse them in PHP myself? For example, when I started this last week, I simply made a string of my data with a pipe '|' separator. In my case, I'm making Soccer players for my game and they're stored as objects, with name/skills etc. So my string would look something like 'John Smith|300|400|100|200' etc. So I'd send that to the PHP file as data, then just 'explode' it in PHP and update my tables with the resulting array.

    Now the thing is, not only did I find that very easy to understand, but it's also easier at the C2 side, because the players are already stored as objects. So to create the string I could do something like 'Str = Str & Player.Name&'|'&Player.Age&'|' ' etc. Nice and easy. What I have to do now is, put the values into the array first, then send the array.AsJSON.

    Also on the PHP side of things, I found it very easy to just parse the string with explode, then put the separate elements into my table.

    When I got stuck and explained this on some PHP boards, they basically told me it wasn't a good method and I'm better of using JSON, but never really explained why. I'm not sure if they're worried that I'm 'reinventing the wheel', because if that's all it is, frankly I'd rather use my own wheel that I understand... and it's actually easier anyway. I suppose there's also the problem that maybe I'm adding extra bytes to my string with the separators, but the JSON string looks huge anyway and has loads of extra characters. Or is it a security issue? If it's security, I'd rather go for the most secure method. But if they're suggesting that JSON is the easier method, maybe it is for C++ programmers etc, but for C2 it doesn't seem to be, and building my own strings is something I'm comfortable with.

    Any ideas? Is my method ok in your eyes?

  • Not sure I have any links, but where are you stuck? If you use layoutright(mylayer) - layoutleft(mylayer) you'll get the correct width of your window, unless you've done some other changes (not sure if it works if that layout is scaled/zoomed etc).

  • Does your table have an ID column? If it does, then when you retrieve the data, retrieve the ID too and send it to C2, and store it with your object/array/whatever. Then when you send it back to be updated, send back the ID too, so that you know which row you're updating.

    The MySql for updating goes something along the lines of 'UPDATE MyTable SET Age = Value WHERE ID = MyID'.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I had something similar in a space game I wrote last year ( http://korelos.clay.io/ ). I need the ships to follow and attack the player ship, though not necessarily directly on top of it. It turned out to be very simple, what I did was have the ships constantly move towards a point near the player ship (adjusted slightly on both axes by a random number, e.g -100, -100 so they move to a point above/left of the ship). Then they just constantly move towards that point, by changing their angle to the correct angle (and you can use bullet behaviour to keep the car moving). Every 5 seconds or so, change the random point that they're heading for, to make them bob about to different positions (makes them look as if they're trying manouvers etc).

  • I had some problems with this at first, there are some more detailed answers on the forums. I always make sure that I get my own values whenever I need them, using layoutright(layer) - layoutleft(layer) or something similar.

  • Ah yes. Families are very useful in situations where you've already picked one object and then suddenly require all of the same objects in the subevents (you can't access them because you've already picked one). For example where you need to compare a value of one object against all of the same type of object. You can do it with variables but families are nicer usually.

  • I'm in a similar stage to you, so I may be able to help. I've been working away at communicating with a database for the past week, so I'm still in the early stages, but I'm able to retrieve info, update it etc, just the basics.

    From what I understand, you want to send a value from C2 to your database, to update it, presumably that value has already been collected from the database earlier?

    So (you probably know most of this), if you already have your value in C2 and want to send it to your database, you need to POST (not update), I think. Actually I'll be honest, I haven't even looked at the method section yet. All I do in your situation is, I send the information in the data, using the default method, then collect it in my PHP file and do the MYSql work in PHP. It's fairly simple, just takes a bit of getting used to (PHP isn't very complicated anyway, just taking me a while to get the hang of the syntax).

  • It's not so much that the information is stored in the 'first' object, as in the default object as created in the editor. Say you deleted the existing object when starting your game (as I often do), at this point you have zero of those objects. If you then create a new object of that type, it begins with the default properties as laid out in the editor. So yes, if you want certain properties upon setup, set them in the editor.

    Honestly, C2 is awesome but it does have a few peculiarities which you need to get your head around (they're usually very good and helpful, just not entirely clear until you understand the flow of the engine better). I personally delete most of my objects on start of layout and when I create my own, set my own values during run-time anyway, just to be clear in my own head.

    By the way, I'm not absolutely 100% sure that everything I just said is even right, so double-check the values during runtime with a text-box or something (or the debugger).

  • Yay, thank you. I'm sure I would have worked this out myself eventually, but this will save me loads of time. I've programmed in BASIC for 30 years, so transitioning to PHP is taking some time due to the different syntax. I'm getting there, but even the simplest things are taking me hours as I try to work out the new syntax. As I said, this will save me hours, so thank you

farflamex's avatar

farflamex

Member since 7 Oct, 2012

Twitter
farflamex has 15 followers

Trophy Case

  • 12-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Forum Patron Made 500 posts in the forums
  • x2
    Popular Game One of your games has over 1,000 players
  • Famous Game One of your games has over 10,000 players
  • RTFM Read the fabulous manual
  • Email Verified

Progress

18/44
How to earn trophies