changing variables or constants

3 views
Skip to first unread message

Eric F.

unread,
Sep 16, 2011, 9:10:21 AM9/16/11
to jacl-discuss
hello,

I'm trying to alter some values, for testing different states in the
game.

First of all, I don't really understand the differences between
constants and variables in JACL.

I'd like to create a variable which could be used between several
object. For example, following the manual:

at the beginning of the game:
constant REPONSE 2

in a {talk_to... } function:

getyesorno player(REPONSE)
if player(REPONSE) = 1

It's working, the problem is when using this structure, it will alter
other variables/constants in the player: the "kryten" object will be
listed in the room description because now the player/kryten's mass is
0 or 1, and no longer 100.

A workaround is to create some "global" variable, called for example
PLAYER_REPONSE and don't link it to the object called "player".

At another place, I'm using this code:

constant TIME_TALKED_TO 0

/.../
set lucien(TIME_TALKED_TO) + 1

Instead of changing this value, it will displace the object (a NPC) to
another location. I can send you the complete code if needed.

Thomas Schwarz

unread,
Sep 17, 2011, 3:03:36 AM9/17/11
to jacl-d...@googlegroups.com
Hi Eric,

a constant is a fixed value. This can't be changed after its definition.

Example:
constant footer_image "/images/top.jpg"
constant hoursperday 24

A variable is a value which may be changed and used as container for values etc.

Example for strings:
----------------------------

# Declaration
string text_variable

# Usage in the program, loops, etc.
setstring text_variable "This is a text"

Example for numeric integer vars:
-----------------------------------------------

# Declaration
integer my_number

# Usage in the program
set my_number = another_number + 20


What you in your examples do is changing object/player PROPERTIES.
These are addressed using "()", e.g. player(mass).
Here is a list of object properties:

# OBJECT PROPERTIES

#object_label(parent)    0     object_label(index)        8
#object_label(capacity)    1     object_label(status)    9
#object_label(mass)        2     object_label(state)        10
#object_label(bearing)    3     object_label(counter)    11
#object_label(velocity)    4     object_label(points)    12
#object_label(next)        5     object_label(class)        13
#object_label(previous)    6     object_label(x)            14
#object_label(child)    7     object_label(y)            15
#The properties next, previous, child, index, status, state, counter, points and class
#have no pre-determined meaning for objects. You are free to set and test these values as required.

The values for "parent", "capacity", "mass", and so on are nothing else than predefined constants with the values 0, 1, 2, etc.

So what you did with your REPONSE constant is change the "mass" property of your player.
Because you did set "REPONSE" to 2 and this is the same as "mass".
If you set player(REPONSE) to something you do nothing else that changing "player(mass)".

I hope this helps somewhat. You should read in the manual about constants, variables and object properties for further information.

Kind regards
Thomas

Stuart Allen

unread,
Sep 17, 2011, 3:46:44 AM9/17/11
to jacl-discuss
Hi Guys

I've probably had a bit too much red wine this afternoon to give a
coherent answer but I'll try.

As Thomas pointed out, but using a constant to reference an element of
an object you are essentially only renaming an existing property. This
probably isn't so bad when you pick an property such as 'bearing',
'velocity', 'x', 'y', 'counter', basically any of the general purpose
properties. At the moment this isn't very clear in the manual, I
should make it better. Unfortunately JACL doesn't allow you do create
a new object subclass and add brand new elements in the way that a
full object-oriented language would.

So the end result is that a constant is just a constant like any other
language. The best way to think of it is that each object has 16
elements, numbered 0-15. Some of those properties have special
meanings such as 'parent' and 'mass' while some only have meaning when
the object is used in a very specific way. You can think of the names
like parents as nothing more than predefined constants. For example
'constant parent 0'. This just means that instead of saying 'ball(0) =
bag' your can say 'ball(parent) = bag' to make things more readable.
By defining another constant that equals 0 you are giving yourself two
names that you can use to refer to the property '0', but it doesn't
change the fact that certain library code will expect that property to
contain a certain type of information, ie. the number of the object
that is the parent of that object.

So wrap up, the RESPONSE constant in the manual should really be set
to something like 9 that is only then overriding 'status', a property
that doesn't have any really significant meaning to any of the library
code.

The OBJECT PROPERTIES table that Thomas posted is the main reference
table you need when picking a constant to override.

I hope this makes sense, if not I'll try again tomorrow when I'm more
lucid.

Hope you are all well,
Stuart

Rob

unread,
Sep 16, 2011, 10:46:14 AM9/16/11
to jacl-d...@googlegroups.com
Hello,

Constants in JACL never change, unlike variables. This is the same in
theory in almost every programming language.

In JACL, every object has an array of properties. The reason you are
having problems is because you are modifying those properties. I.e.
Location is 0, Mass is 2, etc.
You should make sure the properties you are referring to, using
constants, are not used by the game, e.g. you are not modifying the long
desc, mass, location, etc.

Sadly creating objects in JACL is not possible yet, but if you'd like to
avoid the hassle of checking what property is what, you can set up
global variables, though it may become a bit tedious.

Hth,
Rob

Eric F.

unread,
Sep 21, 2011, 3:26:23 AM9/21/11
to jacl-discuss
thank you, I understand better my mistake now. Again, I was trying to
use JACL like I was used to in Inform 6.

I'll use global variables instead, it will be the same for the kind of
project I'm designing.
Reply all
Reply to author
Forward
0 new messages