Hmmm - Maybe I just can't fathom it...

I have taken a snoop at the topic 'NPC random pathfinding' to see if it helps me with my quandary and in a way it is sort of what I am trying to achieve, but for the life of me I can't get my head around it, maybe just data overload and no coffee.

I have created a set of 4 platforms 1 - 4 and I want a robot kong to go on the platforms in order 1,2 ,3,4 and so on. (I can randomise it later).

So far I have set up a START SCRIPT to sort my variables and list:

game.platform_list = NewStringList()
game.platform = Split("platform_1;platform_2;platform_3;platform_4", ";")
for (i, 0, 3) {
//
// check list has been created
//
list add (game.platform_list, game.platform[i])
msg (game.platform[i])
}

I have created the four platforms and named them as in the SPLIT list above. (with thanks to K.V, mrangel and The Pixie from past posts, the list works - woohoo!)

Now moving Kong Bot lol:

This is where the errors show big time and where my limited ability is showing itself in glorious flourish.

On a timer, I have this to move the Kong Bot. The 1 to 4 timer works no problem (0 - 3 in fact) and prints the correct platform, but what I want to know is why won't it move the Kong Bot or even myself, the player, without throwing up an error.

if (game.player_var < 3) {
  game.kong_var = game.kong_var + 1
}
else {
  game.kong_var = 0
}
msg (game.kong_var)
msg (game.platform[game.kong_var])
MoveObject (kong, game.platform[game.kong_var])

Sorry to be a pain,

-=Darchy=-


Your initialisation is doing the same thing twice. The Split function gives you the string list, no need to create a second one.

game.platform = Split("platform_1;platform_2;platform_3;platform_4", ";")

The script that is giving you errors, however, looks almost okay as far as I can see, but I think the attribute on the first line should be "kong_var", not "player_var". I would guess the issue is that you need to give "kong_var" an initial value.

Otherwise, paste the error into your next post (if it is huge, just the first few lines).


Thanks The Pixie,

I understood and trimmed my Start Script to this:

game.kong_var = 0
game.platform = Split("platform_1;platform_2;platform_3;platform_4", ";")

sorted out my dodgy declared variable and no more errors until I go to swap kong with the player

// Move Kong script works.
if (game.kong_var < 4) {
  MoveObject (kong, game.platform[game.kong_var])
  game.kong_var = game.kong_var + 1
}
else {
  game.kong_var = 1
}
msg (game.platform[game.kong_var])
// Move player when possessed by Kong does not work.
if (game.kong_var < 4) {
  MoveObject (player, game.platform[game.kong_var])
  game.kong_var = game.kong_var + 1
}
else {
  game.kong_var = 1
}
msg (game.platform[game.kong_var])

This is the error I get:

Error running script: Error evaluating expression '(not GetBoolean(game.pov.parent, "visited")) and HasScript(game.pov.parent, "beforefirstenter")': GetBoolean function expected object parameter but was passed 'platform_1


Instead of MoveObject (player, game.platform[game.kong_var]), try:

obj =  GetObject(game.platform[game.kong_var])
MoveObject (player, obj)

Just a guess.

I can't test it at the moment.


Hi K.V,

Sadly that throws up this:

Error running script: Error compiling expression 'GetObject(game.platform[game.kong_var])': FunctionCallElement: Could find not function 'GetObject(Object)'

It's odd (well to me anyway) that I have created the object name string on numerous occasion and in a couple of ways from adding a variable and converting it to a string and tacking that onto the end on the object name. I am sure it has to have something to do with the way I am manipulating the player, prior to placing him in a room or in this case a platform.

I don't want to reveal too much at the moment and I suppose this will be okay.

Imagine if you will, a four platform screen in this case 'Donkey Kong'.
When you enter the room, Kong throws a barrel at you and then proceeds to roll you from top to bottom of the platform 1 to the bottom of platform 4. (A transit code of sorts)
By carrying a certain item you can prevent this happening, that part is easy - don't run the scripted if carrying the object and flag Kong.

Thanks,
-=Darchy=-


Okay, I tested this, but I'm guessing at a few aspects of your game:

// Move Kong script works.
if (game.kong_var < 3) {
  new_platform = game.platform[game.kong_var]
  MoveObject (kong, GetObject(new_platform))
  game.kong_var = game.kong_var + 1
}
else {
  game.kong_var = 1
}
msg (game.platform[game.kong_var])

I changed if (game.kong_var < 4) { to if (game.kong_var < 3) {.

Lists begin from 0, so your list goes like this:

  • game.platforms[0] = platform_1
  • game.platforms[1] = platform_2
  • game.platforms[2] = platform_3
  • game.platforms[3] = platform_4

I almost changed

else {
  game.kong_var = 1

to

else {
  game.kong_var = 0

That should start you back from platform_1, but you said it printed everything correctly, so I thought maybe you only wanted Kong to be on platform_1 once. Either way, if it called for game.platform[4], that would throw an error because game.platform[3] is the last string in that list.


Don't ask me why GetObject(game.platform[game.kong_var]) throws that error but the following does not:

new_platform = game.platform[game.kong_var]
MoveObject(kong, GetObject(new_platform))

It's something to do with the way Quest passes parameters, variables, and string items, I guess.


Sorry K.V - I am back to my original bank of errors with that line - That was how I interpreted it last time and ended up here.

Error running script: Error evaluating expression '(not GetBoolean(game.pov.parent, "visited")) and HasScript(game.pov.parent, "beforefirstenter")': GetBoolean function expected object parameter but was passed 'platform_1'
platform_1
Error running script: Error evaluating expression 'GetAllChildObjects(room)': GetAllChildObjects function expected object parameter but was passed 'platform_1'
Error running script: Error evaluating expression 'GetAllChildObjects(room)': GetAllChildObjects function expected object parameter but was passed 'platform_1'
Error running script: Error evaluating expression 'GetBoolean(room, "transparent")': GetBoolean function expected object parameter but was passed 'platform_1'
Error running script: Error evaluating expression 'GetAllChildObjects(newParent)': GetAllChildObjects function expected object parameter but was passed 'null'

this is the whole code here:

START SCRIPT

game.kong_var = -1
game.platform = Split("platform_1;platform_2;platform_3;platform_4", ";")

TIMER SCRIPT

if (game.kong_var < 3) {
  game.kong_var = game.kong_var + 1
}
else {
  game.kong_var = 0
}
obj = game.platform[game.kong_var]
MoveObject (player, obj)
msg (game.platform[game.kong_var])

Thanks again - I appreciate your time and help.


Sorry, I just edited that post.

I tested it more extensively now.

Change MoveObject (player, obj) to MoveObject (player, GetObject(obj)), and watch the magic!

(Fingers crossed.)


NOTE: You're moving the player in this code (not Kong). I just added the GetObject in the place Quest likes it.


You know you've got it right when the message displays like this:

Object: platform_2

msg (game.platform[game.kong_var]) prints this :

platform_2

That tells us that game.platform[game.kong_var] is outputting a string, not an object, and you can't move an object to a string during play.


Doing GetObject(game.platform[game.kong_var]) throws an error, saying it is already an object. This is the confusing part, and I wish I understood it.

But I just learned that we can cheat like this:

x = game.platform[game.kong_var]
x = GetObject(x)

Now x is actually an object, not a string.


I created two rooms for the test: platform_1 and platform_2.

Here's my test script:

game.kong_var = 1
game.platform = Split("platform_1;platform_2", ";")
new_platform = game.platform[game.kong_var]
msg("<b>game.kong_var:</b> "+game.kong_var)
msg ("<b>game.platform[game.kong_var]:</b> "+game.platform[game.kong_var])
msg ("<b>GetObject(new_platform):</b> "+GetObject(new_platform))
MoveObject (player, GetObject(new_platform))

The output:


You are in a platform_1.
game.kong_var: 1
game.platform[game.kong_var]: platform_2
GetObject(new_platform): Object: platform_2

You are in a platform_2.


Cheers K.V - I will try that out later. I seem to be confusing my strings with my objects.

This below is familiar, thanks

x = game.platform[game.kong_var]
x = GetObject(x)

Answering off the top of my head, so sorry if I get some of the function names wrong.

Doing GetObject(game.platform[game.kong_var]) throws an error, saying it is already an object.

Not quite.

game.platform[game.kong_var] is equivalent to ListItem(game.platform, game.kong_var) ... and ListItem has an unspecified return type.

GetObject is a built-in function, so tests the declared type of its parameters before evaluating them. It throws an error because the result of ListItem might be an object, and because it's already found an error, it never gets around to checking the actual type.

So you have to assign the result to a variable first (as you found); or explicitly use StringListItem.


Oh!

That's why StringListItem worked and plain ListItem didn't in a totally different script a few days back.

I got around it, but I didn't know why (which perturbs me).

Thanks, mrangel!


Hi guys and thanks for your input and advice. Firstly, sorry for the delay in responding, been a bit hectic here, but I had to come back to report.

With the existing code and changing the variable names along with the advice of you guys I have this:

START UP SCRIPT

game.kong_var = -1
game.platform = Split("platform_1;platform_2;platform_3;platform_4", ";")

ON A 2 SECOND TIMER FOR TEST*

if (game.kong_var < 3) {
  game.kong_var = game.kong_var + 1
}
else {
  game.kong_var = 0
}
new_plat = game.platform[game.kong_var]
new_plat = GetObject(new_plat)
MoveObject (player, new_plat)

It works perfectly!!! - Random jumps, backwards, forwards and ping-pong - I can do the lot. The reason it was important to move the player was because at a later point there is a similar event without being possessed by Kong. Considering I almost felt like throwing the towel, this has allowed me to progress a bit more. Thanks to you all.

If I am not back before - please have a good Christmas / Holiday

regards,
-=Darchy=-


Data/Attribute/Variable/Value Types:

a 'StringList' holds 'string' Values for its items, so if you need it to be an 'object' Value, either you use: 'GetObject (STRING_VALUE)' or you use an 'ObjectList' (which holds 'object' reference/ponter Values as its items, instead of 'string' Values), instead of using a 'StringList'

// String List Attributes:

// as coding tag block:

<object name="example_object">
  <attr name="example_stringlist_attribute" type="stringlist">
    <value>joe</value>
    <value>jim</value>
  </attr>
</object>

// or, horizontal format/style:

<object name="example_object">
  <attr name="example_stringlist_attribute" type="simplestringlist">joe; jim</attr>
</object>

// using scripting (method 1):

example_object.example_stringlist_attribute = split ("joe; jim", ";")

// using scripting (method 2):

example_object.example_stringlist_attribute = NewStringList ()
list add (example_object.example_stringlist_attribute, "joe")
list add (example_object.example_stringlist_attribute, "jim")

// Object List Attributes:

// as coding tag block:

<object name="example_object">
  <attr name="example_objectlist_attribute" type="objectlist">
    <value>joe</value>
    <value>jim</value>
  </attr>
</object>

<object name="joe">
</object

<object name="jim">
</object>

// or, horizontal format/style:

<object name="example_object">
  <attr name="example_objectlist_attribute" type="objectlist">joe; jim</attr>
</object>

<object name="joe">
</object

<object name="jim">
</object>

// using scripting:
// ('joe' and 'jim' needs to be actual existing Objects, see above or below example, for having 'joe' and 'jim' as Objects)

create ("joe")
create ("jim")
example_object.example_objectlist_attribute = NewObjectList ()
list add (example_object.example_stringlist_attribute, "joe")
list add (example_object.example_stringlist_attribute, "jim")

you can create local/temporary 'Variable' VARIABLES too, but I'm just showing you how to do them as 'Attribute' VARIABLES in this post. Let me know if you want/need to use 'Variable' VARIABLES and don't know how to use them: you need help on their usage and/or syntax.


@hegemonkhan - I shall take a deeper look at that when I get a chance. Thanks for the extra info.


oops, I forgot to show how you'd use 'GetObject (xxx)' with a 'String List', my bad...

// String List Attributes:

// as coding tag block:

<object name="example_object">

  <attr name="example_object_attribute" type="object">unknown_object</attr>

  <attr name="example_stringlist_attribute" type="stringlist">
    <value>joe</value>
    <value>jim</value>
  </attr>

</object>

<object name="unknown_object">
</object>

<object name="joe">
</object>

<object name="jim">
</object>

// or, horizontal format/style:

<object name="example_object">

  <attr name="example_object_attribute" type="object">unknown_object</attr>

  <attr name="example_stringlist_attribute" type="simplestringlist">joe; jim</attr>

</object>

<object name="unknown_object">
</object>

<object name="joe">
</object>

<object name="jim">
</object>

// using scripting (method 1):

create ("example_object")
create ("unknown_object")
create ("joe")
create ("jim")

set (example_object, "example_object_attribute", unknown_object)
// or: example_object.example_object_attribute = unknown_object

example_object.example_stringlist_attribute = split ("joe; jim", ";")

// using scripting (method 2):

create ("example_object")
create ("unknown_object")
create ("joe")
create ("jim")

set (example_object, "example_object_attribute", unknown_object)
// or: example_object.example_object_attribute = unknown_object

example_object.example_stringlist_attribute = NewStringList ()
list add (example_object.example_stringlist_attribute, "joe")
list add (example_object.example_stringlist_attribute, "jim")

// --------------------------------------------

using 'GetObject' with 'String List Attributes', examples (using both 'Variable' VARIABLES and 'Attribute' VARIABLES, so you can see the difference between them somewhat --- a bit more explanation is probably needed, but it's too much work, I'm lazy, lol) and some explanations:

// lists, number their items (this numbering is known as their 'index number', in an old reference to how library's books are/were organized by their 'index' numbers) starting with 0 (zero), NOT 1, you get used to it after a while and it's for a good reason to start with 0 (zero).

// this means that the last index number (the last item in the list), is: ListCount (xxx) - 1
// 'ListCount (xxx)' counts the number of items in the list, and returns that count number
// so, using our example, we've got 2 items in the list ("joe" and "jim"), which means: "joe" = index number 0, and "jim" = index number 1, but index number 2 is 'out of range/bounds' (outside of our list), and thus causes huge issues, and thus returns errors

string_variable = StringListItem (example_object.example_stringlist_attribute, 0)
// string_variable = "joe"
example_object.example_object_attribute = GetObject (string_variable)
// example_object.example_object_attribute = joe

string_variable = StringListItem (example_object.example_stringlist_attribute, 1)
// string_variable = "jim"
example_object.example_object_attribute = GetObject (string_variable)
// example_object.example_object_attribute = jim

string_variable = StringListItem (example_object.example_stringlist_attribute, 2)
// ERROR!!!!! There is no 3rd item in the list!

// using randomization:

// (I broke them down into individual lines, as it is easier to understand, but you can combine them all into a single line, but you got to make sure you got the syntax and parenthesis correct, easy to mess up, another reason to break it up into multiple lines)

list_count_number_integer_variable = ListCount (example_object.example_stringlist_attribute)

last_index_number_integer_variable = list_count_number_integer_variable - 1

randomly_selected_in_bounds_index_number_integer_variable = GetRandomInt (0, last_index_number_integer_variable)
// randomly_selected_in_bounds_index_number_integer_variable = [0 or 1]

randomly_selected_stringlist_item_string_variable = StringListItem (example_object.example_stringlist_attribute, randomly_selected_in_bounds_index_number_integer_variable)
// randomly_selected_stringlist_item_string_variable = ["joe" or "jim"]

randomly_selected_object_variable = GetObject (randomly_selected_stringlist_item_string_variable)
// randomly_selected_object_variable = [joe or jim]

using 'Object Lists' require much less code/work (as you don't have to use the 'GetObject' to convert the string list's string items/values into object reference/pointer values), but there's still a good reason to use 'String Lists' too, there's pros and cons to both of them, and/or you may need/want to use/have both (Object Lists and String Lists) as well too (or not).


Log in to post a reply.

Support

Forums