Home News Features Games Authoring Community Forums About Contact
   

May 21, 2013, 04:17:58 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Dynamic object pointers?  (Read 1186 times)
rustybroomhandle
Newbie
*
Offline Offline

Posts: 13


« on: September 01, 2012, 08:20:02 AM »

Just curious about something. Is it possible to store objects in variables?

Here's an example that doesn't work but illustrates what I mean:

var fruit = banana;
say (ego, fruit.colour);

objectType apple ("") {
    var colour = "Red";
}

objectType banana ("") {
    var colour = "Yellow";
}
« Last Edit: September 01, 2012, 08:24:11 AM by rustybroomhandle » Logged
Trumgottist
Maker of SLUDGE
Longtime Member
*****
Offline Offline

Gender: Male
Posts: 1162



WWW
« Reply #1 on: September 01, 2012, 09:06:48 AM »

That sort of thing is not possible, no. Objects in SLUDGE aren't as complex as in languages like, for example, C++. Or in other words, there is no way to indirectly access a variable inside an object.
Logged

"Programming is the computer game that makes all others possible." - Ron Newcomb
rustybroomhandle
Newbie
*
Offline Offline

Posts: 13


« Reply #2 on: September 01, 2012, 09:32:31 AM »

Ahh, ok, was just wondering. By the way, we made our Ludum Dare 24 Jam entry last weekend using OpenSLUDGE.

We didn't quite finish, but we're pretty happy with what we had thus far.

http://www.ludumdare.com/compo/ludum-dare-24/?action=preview&uid=10871
Logged
Trumgottist
Maker of SLUDGE
Longtime Member
*****
Offline Offline

Gender: Male
Posts: 1162



WWW
« Reply #3 on: September 01, 2012, 10:22:55 AM »

You did that during Ludum Dare? That's what, 24 hours? Very impressive!
Logged

"Programming is the computer game that makes all others possible." - Ron Newcomb
rustybroomhandle
Newbie
*
Offline Offline

Posts: 13


« Reply #4 on: September 01, 2012, 11:30:29 AM »

Well, the Jam gives 72 hours, and we had a boatload of people show up to help build the scenes and sprites.
Logged
Trumgottist
Maker of SLUDGE
Longtime Member
*****
Offline Offline

Gender: Male
Posts: 1162



WWW
« Reply #5 on: September 01, 2012, 05:35:09 PM »

Ah. Still impressive, but not as crazy. Smiley
Logged

"Programming is the computer game that makes all others possible." - Ron Newcomb
ad7venture
Longtime Member
*****
Offline Offline

Gender: Male
Posts: 3130



WWW
« Reply #6 on: September 01, 2012, 08:29:49 PM »

I enjoyed that, thanks.  The scenes looked quite nice made in Minecraft.  I realize it was rushed, but if you wanted to improve it, idle animations would help quite a bit, and a rock paper scissors approach to fights would have also helped along with a few more interactive objects to add background and interest.  It was an excellent proof of concept and I hope others will try that type of game with Sludge.
« Last Edit: September 01, 2012, 08:31:26 PM by ad7venture » Logged
rustybroomhandle
Newbie
*
Offline Offline

Posts: 13


« Reply #7 on: September 02, 2012, 08:40:07 AM »

@ad7venture - I have been working on it and there's actually a proper turn-based combat system in the game now. The main character has three actions to choose from, and each monster only gets one type of attack. Monsters also have stats. I can define a list of possible monsters to appear in a scene and it will place a random one, or I can specify currentMonster = "chicken1" and then call beginCombat() to start a fight with it.

My question in the OP actually had to do with defining monster types as objects.

I've done it in a different way now. I'll post it here when done. The code is ugly as sin and perhaps not done in the best way, but heck maybe it can still be educational.

Most of the remaining work is the animations and generally to make it all a bit less static. Some things for the mc to look at and comment on will definitely help.
Logged
Trumgottist
Maker of SLUDGE
Longtime Member
*****
Offline Offline

Gender: Male
Posts: 1162



WWW
« Reply #8 on: September 02, 2012, 10:58:21 AM »

To give a more detailed answer to the original question, I think the cleanest way to do what you ask about in SLUDGE would be something like this:

Code:
# This is the fruit system
var fruitcolour;
objectType getColour("") {}

objectType apple ("") {
    event getColor {
        fruitcolour = "Red";
    }
}

objectType banana ("") {
    event getColor {
        fruitcolour = "Yellow";
    }
}


# And this is how it's used

var fruit = banana;
callEvent (getColour, fruit);
say (ego, "The fruit is " + fruitcolour);

Or, on second thought, I think I like it better using flags (at least for a limited range of colours):

Code:
sub getFruitColour(fruit) {
    if (hasFlag(fruit, fRED))
        return "Red";
    if (hasFlag(fruit, fYELLOW))
        return "Yellow";
    return "Multicoloured as a rainbow";
}

objectType apple ("") {
    flags fRED;
}

objectType banana ("") {
    flags fYELLOW;
}

var fruit = banana;
say (ego, "The fruit is " + getFruitColour(fruit));
Logged

"Programming is the computer game that makes all others possible." - Ron Newcomb
rustybroomhandle
Newbie
*
Offline Offline

Posts: 13


« Reply #9 on: September 02, 2012, 11:26:15 AM »

Ahh, thanks for that. What I ended up doing is similar to your second example but using a string for the "fruit" name, and doing "if" on that instead of flags. At least I know now I wasn't completely off-track, or ended up doing something that could have been done tidier.
Logged
Trumgottist
Maker of SLUDGE
Longtime Member
*****
Offline Offline

Gender: Male
Posts: 1162



WWW
« Reply #10 on: September 02, 2012, 12:12:42 PM »

Or perhaps (once I get started, it's not so easy to stop):
 
Code:
sub getFruitColour(fruit) {
    if (hasFlag(fruit, fRED) &&  hasFlag(fruit, fYELLOW))
        return "Orange";
    if (hasFlag(fruit, fRED))
        return "Red";
    if (hasFlag(fruit, fYELLOW))
        return "Yellow";

    # No colour - maybe it is a bug rather than a fruit?
    return "Black";
}

objectType peach ("") {
    flags fRED, fYELLOW;
}

Not so useful when talking about fruits and colours, but if the system is growing more complex, this is where flags can come in handy. (Not as useful as having pointers. I've missed having pointers too, on occasion, but I don't think it'd be worth it to add that complexity to the language.)
« Last Edit: September 02, 2012, 12:16:35 PM by Trumgottist » Logged

"Programming is the computer game that makes all others possible." - Ron Newcomb
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.8 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
 
Unauthorised reproduction of anything on this website is not allowed without our written consent.
Materials on this site are the property of their respective owners. Copyright © Adventure Developers. All rights reserved.