How do I tell my character to move to the coordinates of a random object on the map?


#1

I just got to the Kithgard Brawl level in the Kithgard Dungeon, and I’m having trouble with picking up the items.

Since it’s random, I can’t just use an ‘if’ statement with the coords of an item’s location after it pops up, because once I submit the code it’s a different location from the testing part, and he’ll move to an empty spot (most likely).

What I want to be able to do is tell my character to move to an item’s exact coordinates based on a variable that includes the coordinates in the variable, so I can basically just write an ‘if’ statement when an item appears, and he’ll go pick up the item no matter where it might be. Then go back to attacking peeps after the item is acquired. I’m just not sure how to put coordinates of a specific object into a variable.


#2

The only item I can think of in that level to pick up is the healing potion.

If you don’t have glasses that can find items (wooden glasses+), then you will have to wait until you do the level that gives them to you (see this post (it is pinned to the top of the list if you need to find it again later).


#3

Haha, silly me, I didn’t bother checking the directions on the glasses again.

I don’t really understand why that code there works, but thanks for the hint.


#4

It is kind of the same quest but in a few difference paths in some sense.
Here’s a picture shown what I’ve done:

Thanks for reading!
Too small? Try clicking on the picture!


#5

Yup, running is a valid way to “survive for X seconds”, and works for a repeat or three, by then you start to collect a big group of archers in the middle who turn you into a pin cushion. :person_frowning: :round_pushpin: :smile:

The first level or two, I try beating the snot out of them and if that doesn’t work I try running scared, and when that doesn’t work I go for a combo approach, (run a little, kill a little, run some more, kill some more…)


#6

You need to prioritize items over enemies. As there’s always a streaming line of them. Before he can move to it though, he needs to find it first like, item = this.findnearestitem; once he finds that, though, all he has to do is move to the item using the var item and the pos of item.


#7

How might one make sure that the item is prioritized?

My example javascript pseudocode-ish stuff
// jshint asi:true
loop {
	//variables here
	//items
	//targets
	if (item) {
	this.say("Item!!!")
	var pos = item.pos
	this.moveXY(pos.x,pos.y)
	}
    else {
        if (target) {
            var tPos = target.pos
            if (canFight) {
                fight
            }
            else {
                moreFighting
            }
        }
    }
}

When I use this layout my character doesn’t go for the item while enemies exist. Might this be because of something like " var target = priorityTargets || enemy || null " ?? I was thinking that this method of choosing a target would only give you one to attack and then make you have to recalculate it to get a new target within the next loop around.