An alternative to if-scripts?

chellkafka
I'm trying to work on a highly reactive piece, where there are a lot of sensible variables, that the player can influence. The problem is, I'm using variables and if-scripts to get this done, which makes for extensive scripting, I have to account for all the different variable states and all the different combinations of those states, like if there would be the possible states A, B and C, I would also have to account for AB, BC, AC and ABC, and so on.
I work with a lot of variables and states, so I create ridicolously large scripts, which take forever to load or change at times.
So my question is, is there a more streamlined way to do this, so the scripts can load faster and they are more overseeable.
I am aware that I cannot reduce the amount of writing text for all the states, but I simply wonder if I could reduce some workload on the technical side of things.

Silver
If I'm understanding what you're asking correctly I would create an object for each state so you'd have:

object ab in the room (if that's it's present state) and then I'd have a room set up to store objects which isn't connected to any other room in the game where there would be:

object ac
object bc
object abc

So when the object changes state I'd simply run a script that swaps the object in the room with the one in its new state.

Silver
Is that what you mean, or something else?

Silver
If its the room itself that changes state you could still do the same as above just make the objects scenery objects. Then run an if script like

if object ab is in room then blah blah
else if object ac is in room etc

Silver
The coders probably know a simpler solution though.

chellkafka
No, it doesn't seem to address the issue. To be more clear, here is an example of my game.

The main principle of the game is, that you "walk down a road", encounter random situations and then deal with them how you like, within those interactions I created for that situation. One of the encounters is, a dead body lying in the middle of the road. You can now, simply walk on by, you can examine the body, you can harm the body, you can desecrate the body and you can bury the body. Furthermore, if you've found some items before, you can use those items on the body, like, if you found a bean before, you can "implant" the bean into the body. And a couple other things. So I created for all the objects, the accordingly variables, like body.harmed, body.desecrated, etc. which is easy of course, and the influence of the player on those variables, is also fairly easy to implement. But I also want to reflect the changes the player made, in every appropriate text, for example, when the player encounters this place again, there should be a text, to reflect all the changes, the player has made, and so far I simply used if-scripts, like

if body.buried=false
if body.harmed=0
if body.desecrated=false
if body.wears=0
etc.

so, I did that for all the variables, for all the else if and else statements, all the combinations, and it's just huge.
I'd just like to know, if there's a simpler way, to account for all those variables and states.

Silver
Can you set an attribute for each state and then use the text processor in the room description?

{if object.attribute:text}

jdpjdpjdp
If the options are mutually exclusive, Silver's initial suggestion will work perfectly.

I'll use your example, the body. You have the body in the "room" in its original, unaltered state. Then, in a dummy room (one the player can't access), you have objects for a buried body, a harmed body, a desecrated body, etc. When the player comes along and, for example, harms the body, remove the original body object and move the "harmed body" object into the room in its place. Give them all the same alias, "body", so the player won't even notice the switch, but each object can have its own unique description and interactions with other objects, without the need for endless variables and if statements. Any object with more than one state would just be a unique game object, swapped out as needed, with unique interactions between them.

m4u
I like this post. It happens to me too. So, two solutions have been given:

1. Create different objects with the same alias. Nice idea!
2. Use the text command if. I use it a lot and it works great.

I recommed a third that I use:

3. Switch script function. Someone here can describe better how to use it.

HegemonKhan
if you have a lot of combinations, you got a lot of combinations, I don't think even super advanced parsing~high level coding can do much about this (Jay, Pixie, Pertex, etc, and other coders can correct me if I'm wrong), but you can reduce the, lines ~ character count, to deal with those combinations, and that is dependant upon coding knowledge, as different designs are better and worse, so I won't be of much help as I still don't know much of coding, let alone advanced coding, you're going to need help from the coders, who know all of the high level coding designs and coding techniques that are still way beyond me.

-------------------

a small bit of help:

if body.buried=false
if body.harmed=0
if body.desecrated=false
if body.wears=0

this shows me that you're using a lot of Boolean (true~false, and Integer flags: 0~1+) Attributes...

for my own example (I'm using this as it's well known if you ever played RPGs):

status effects:

player.poisoned = (true or false)
player.asleep = (true or false)
player.confused = (true or false)
player.paralyzed = (true or false)
player.petrified = (true or false)
player.silenced = (true or false)
etc etc etc

obviously Boolean usage is very cumbersome...

you can reduce the cumbersome-ness, by using: String Attributes

player.condition_string = " (poisoned or asleep or confused or paralyzed or petrified or silenced or etc) "

1 code line instead of (using my example above) 6+ code lines

and, then there's using lists too, if you want to have multiple effects, in effect:

player.condition_stringlist = split ("poisoned; confused", ";")
you add or remove the conditions from the list as you need

now, sometimes using Booleans is useful for what you need to do, sometimes using Strings are useful, and soemtimes Lists are useful, it depends upon the scenario~situation of what you want to do and how you want to do it and what's the best way to do it.

and, there's probably many other (and better) methods too... which are beyond me... more advanced coding methods that I've still got to learn... lol

Silver
The switching objects technique would be how I'd do it. Mainly because I'm not even on the starting rung of coding. It'd solve the problem of the script being impossibly long because you'd just have one script that dealt with which object should be in the room based on how the player interacted with it and then the rest dealt with internally of each object.

So you could have an object called body and an object called desecrated body. desecrating the body object just runs a script to replace the two. You could then add an attribute to them both to manipulate the text in the room description.

You are standing on a country lane and you can see a {if body.untouched:body lying on the floor.{if desacratedbody.whatever:body that has been tampered with.}

That's if I'm understanding attributes correctly. I'm yet to work with them. :?

Silver
Actually the attribute thing needs some thought. Because the object would still have the attribute when removed from the room so the attribute in the text processor would need to reflect that. Maybe there's a better processor command to use. Is there a way to add/remove attributes in a script?

The Pixie
HegemonKhan wrote:if you have a lot of combinations, you got a lot of combinations, ...

This about sums it up.

There may be some mileage in compiling a string to display to cut down on the number of combinations. Something like:
if (not body.buried) {
s = "There is a body here"
if (body.mutalated) {
s = s + ", that is heavily mutalated"
}
if (body.seedplanted) {
s = s + ", with a small tree growing from it"
}
msg(s + ".")
}

That is all I can think of.

chellkafka
Thanks guys, I'll try some of it out, the "an object for every state"-thing sounds good.
I'm also already using integer attributes to cover non-binary states, for some reason the string-attribute didn't work. is there something I have to keep in mind using that?

Silver
You mean with using the command {if object:attribute:text} ?

I have no idea tbh, I was half guessing. It's a shame there isn't one for flags; I see that there's one for gamebooks. I haven't checked if it works for parser games but it's listed as being exclusively for gamebooks in the documentation.

HegemonKhan
String Attribute's Values must be within quotes:

player.condition = "poisoned"

why?

because no quotes on the Value (unless it is numeric, which is a special value, telling quest that it is Type:Integer), tells quest that it is an Object, instead of text~word(s), aka a String.

Object_name.Attribute_name = Value_or_Expression

Object's 'name' String Attribute: Object_name.name = apple
String Attribute: Object_name.Attribute_name = "apple"

apple -> Type: Object
"apple" -> Type: String

--------

<object name="sword">
-> <alias>claymore</alias>
</object>

player.right_hand_object = sword
sword.alias_string = "claymore"

-------

Attribute Types:

http://docs.textadventures.co.uk/quest/types/
http://docs.textadventures.co.uk/quest/ ... bject.html
http://docs.textadventures.co.uk/quest/ ... tring.html

--------

String Attributes:

Object_name.Attribute_name = "Value_or_Expression"

player.alias = "HK"
player.condition = "poisoned"
game.event_flag = "1"
game.greeting = "Hi, my name is HK, what is your name?"
game.y = "x"
player.y = "x"

Object Attributes:

Object_name.Attribute_name = Value (non-numeric)

player.right_hand = sword
player.left_hand = shield
player.parent = room
wizard.parent = tower
game.pov = player
game.pov = HK
game.pov = Chellkafka

Integer Attributes:

Object_name.Attribute_name = Value_or_Expression

player.strength = 100
player.damage = player.sword.damage + player.sword.damage * player.strength / 100

chellkafka
ah, i see, thank you, hegemon.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums