Need Help with Errors on my Game

Hi everyone!

So, I'm a beginner at coding... as in; I can't code. I used the Zombie Apocolypse tutorial and changed it around slightly(to fit my game.) I'm probably going to have to get help with lots of things. But, I'll tell you about my current problem:

(NOTE: I DID NOT ADD ZOMBIE ATTACKS, BECAUSE I COULD NOT GET IT TO WORK.)

So, the weapons in the game, currently are a hammer and a snub nose revolver. I was testing out the combat system(using the hammer) and got this error:

Error running script: Error compiling expression 'GetRandomInt(1, 20) + weapon.attack - target.defence': ArithmeticElement: Operation 'Add' is not defined for types 'Int32' and 'Object'

If you need any more information, I'm happy to give it to you.

(By the way, please dumb things down for me... because I'm very stupid. And, my name is an inside joke.)


Check that your hammer has an attack attribute. That sounds like you failed to set it.


How do I check that?


Is it in the initialization script?


In the initialisation script for the sword, the tutorial probably includes something like

this.attack = 5

You need to check that line is present for all weapons including the player (assuming you're using the web editor. On desktop you could also do it using the Attributes tab; but I think the zombie tutorial doesn't use that)


Well, I think it's the initialization script.

(EDIT: It is, I didn't see your reply.)

Here's the code for the hammer:

hammer.damage = "1d6"
hammer.attack = 3
hammer.critdesc = "You smash the hammer down on #target# (#hits# hits)."
hammer.attackdesc = "You swing the hammer at #target# (#hits# hits)."
hammer.missdesc = "You swing wildly and entirely miss #target#."


Yup, they all have that line(though, "this" is replaced with the name/alias of the weapon.)


Yup, they all have that line(though, "this" is replaced with the name/alias of the weapon.)

It looks like that line is missing or misspelled for one of your weapons. That's the best I can do without looking at your game.

Is there a reason you decided not to use this?


I did have this, but I switched it around to the name/alias to see if that would get it working.


Would a pastebin(something I've never used) help?


If you can share the code, I hope I could find the problem given a little time.


https://pastebin.com/bQAM3Mrz


I think mrangel needs the complete code of your game


I'm not sure how to gather that. Would I have to do it manually?


EDIT:

This is an edit of an edit, I don't want to make new messages too much. So, I've made a pastebin account so I can edit the pastebin to reflect changes and not have to make a new one. So, I've had to make another pastebin. Ignore the other one.

I'm changing the hammer to a baseball bat to have the basic weapon make more sense. I'm also going to change the alias in the initialization script.

For example:

hammer.attack = 3

Is going to be changed to:

this.attack = 3

Here's the link:

https://pastebin.com/FXNsYKvR


If you're using the desktop editor, there's a "full code view" somewhere which lets you see the complete code for the game. Or you can open the .aslx file in Notepad or similar, and copy it from there. Or send the aslx file using something like file.io.

If you're on the web editor, you can still download the aslx file using the 'download' link on the "My Games" listing page, and send it however is more convenient for you.

The easiest way is simply to publish the game (you can set it to be viewable only by people with the link, so you can share a work-in-progress only with people who are trying to help you). The biggest disadvantage of this is that once a game is published, you can't delete it.


However, you can upload the game again with different coding and it replaces the old game code.


Okay, here's the link:

https://textadventures.co.uk/games/view/sedivsza4uu-wjoq4t-b5q/youre-being-watched

It started out as more of a puzzle home-invasion thriller, now it's turned into an action/horror puzzle.

For me, it was kind of like:

What if I could make my own Resident Evil game?


I think I'll use this place as sort of a journal, to keep track of things and also use it as a discussion about my game.

So, I'm going to add a list of things I want to do.

I will give updates if and when I finish them:

Add an alternative load and save system. Make it so saving is only available in certain places(the safe room of the manor, which is the bedroom.)

Add an ability to combine certain items.

Add a fear mechanic, have it so it reduces abilities; as in it worsens your damage roll, your attack etc.

Add an adrenaline mechanic, since stamina is out of the picture(because text adventures are, generally, turn-based) the only thing I can think of currently is that it increases your health.

Make the adrenaline and fear mechanic coincide with each other.

That's all I can think of right now, if you have any other ideas; they would be very welcome.


First up, I notice that your list of parameters to DoAttack is a little confused.

The parameters for DoAttack are weapon, target, attacker, firearm.

When the player does "attack corpse" without a weapon, you run the line:

  • DoAttack (player, player, object)
    so the parameters are:
    • weapon is set to player (that's right; it should use the player's attack and damage values when unarmed)
    • target is set to player (I think that's wrong)
    • attacker is set to object (so that's the zombie)
    • firearm is set to… well, it isn't set. Which is why attacking without a weapon causes an immediate error about the wrong number of parameters.

I think that should be:

  • DoAttack (player, object, player, false)

Similarly, if you have a weapon equipped, the line in the 'attack' command is:

  • DoAttack (player, player.equipped, object, true)
    so the parameters are:
    • weapon is set to player
    • target is set to player.equipped
    • attacker is set to object
    • firearm is set to true, whether or not the weapon is a firearm. I'm guess you want it to be false, so that if the player has the pistol equipped but is out of ammo they can still pistol whip the zombies by choosing "attack" rather than "shoot".

Then you get the arithmetic error. I guess that it's defence, rather than attack, which is giving the error. Because target is set to your weapon, and the baseball bat doesn't have a defence.

So I think the line should be:

  • DoAttack (player.equipped, object, player, false)

Similarly, in the attackturnscript, your line:

  • DoAttack (obj, obj, player)

should probably be

  • DoAttack (obj, player, obj, false)

and in the "shoot" command,

  • DoAttack (player, player.equipped, object, true)

should probably be

  • DoAttack (player.equipped, object, player, true)

I also note that your zombies never attack because attackturnscript is not enabled. Did you disable it for testing?

Your DoAttack stat also uses the weapon having a firearmdamage attribute to determine whether it's a firearm or not, and ignores the firearm parameter. This would mean that you can effectively use your gun after you've run out of ammo, just by choosing "Attack" instead of "Shoot". But I suspect that in reality it will generate another error message.
It also sets the variables damageatt and attackatt but never uses them.

I think your DoAttack function could probably be amended to something like:

    if (firearm and HasString (weapon, "firearmdamage")) {
      damagestat = weapon.firearmdamage
      attackstat = weapon.firearmattack
      weapon.ammo = weapon.ammo - 1
    }
    else {
      damagestat = weapon.damage
      attackstat = weapon.attack
    }
    roll = GetRandomInt(1, 20) + attackstat - target.defence
    damage = DiceRoll(damagestat) * (100 - target.armour) / 100
    if (damage < 1) {
      damage = 1
    }
    if (roll > 15) {
      report = "crit"
      damage = damage * 3
    }
    else if (roll > 10) {
      report = "attack"
    }
    else {
      report = "miss"
      damage = 0
    }
    if (firearm and HasString (weapon, "firearm" + report + "desc")) {
      report = "firearm" + report
    }
    target.hitpoints = target.hitpoints - damage
    AttackReport (GetString (weapon, report + "desc"), attacker, target, 0)

I moved the AttackReport to the end to avoid repeating code inside the if block. In this version, the gun can optionally have attributes firearmattackdesc, firearmcritdesc and firearmmissdesc, in case you want to have different descriptions for shooting or pistol-whipping zombies. A little bit more realism :)

That's all the issues I could find on a quick glance through the code. Hope that's been some help.


Your fix did work, but I seem to have another error.

I hate to keep bothering you, but I have little to no coding knowledge.

Here's the error:

Error running script: Error compiling expression 'weapondamage': Unknown object or variable 'weapondamage'
Error running script: Error compiling expression 'weapondamage': Unknown object or variable 'weapondamage'``

Nevermind, I fixed it. But, I've got more errors.

Error running script: Error compiling expression 'Replace(s, "#Attacker#", CapFirst(GetDisplayAlias(attacker)))': FunctionCallElement: Could find not function 'Replace(Object; String; String)'

EDIT: And this:

Error running script: Cannot foreach over '' as it is not a list

While these are purely visual errors(I think), they make the game look ugly.

EDIT: Again...

That's cool, you already fixed this issue before. A small world.


Okay, final message(until I get another error message :D).

I fixed the first error:

Error running script: Error compiling expression 'Replace(s, "#Attacker#", CapFirst(GetDisplayAlias(attacker)))': FunctionCallElement: Could find not function 'Replace(Object; String; String)'

And the second error:

Error running script: Cannot foreach over '' as it is not a list

Doesn't really matter, since it only happens when you die(well, to be more specific; when the game is finished), it's purely visual and is missable.

Thanks for all the help!

I'll try to keep you updated on the game!


As this is a discussion about my game, I'd like to ask for some advice on some code.

So, I've set up a room called the Puzzle Room where you have to find three medallions to put in each [three] stands. That will open up [a] hidden room(s).

Do you guys have any idea how I might be able to do this?


Error running script: Cannot foreach over '' as it is not a list

This one is really bugging me, as it doesn't make any sense. It seems like ending the game causes the core function UpdateStatusAttributes to generate a whole bunch of different errors, different each time it is run. And most of them seem to be a problem with one of the attributes, or player.statusattributes itself, becoming null. Even thought there's checks for null in that function.

I'm wondering if the game is destroying the player object before finishing the code, which seems very strange; but it's the only explanation I can think of.


I wouldn't worry about it, as I said:

Doesn't really matter, since it only happens when you die(well, to be more specific; when the game is finished), it's purely visual and is missable.


If you want to hide that error, you could try putting:

JS.eval("window.addText = console.log;")

after the finish line.

That will hide any post-end-of-game errors by sending all output to the debugger instead of the screen until the page is refreshed.


It worked, thanks for helping me so much with my game. :)


UPDATE:

Yesterday(very, very late), I added a new addition to the game.

Basically, there are two objects.

A Desk and a Desk Lock.

The Desk is a container, it's not originally open and is locked.

The Desk Lock has a verb called "select".

Now, I'll break down the "select" verb:

So, I used a tutorial to create a menu...
(here is the menu: http://docs.textadventures.co.uk/quest/ask_simple_question.html)

But instead of there being dialogue options, there are combination options.

It started out with three letters: ABC

And eventually turned into: ABCDEF

There are over 150 combinations!

So, basically: the combinations are contained within a new string list...

The code(summarized) for giving a response to a combination goes like this:

After the player chooses, it runs a script with a switch:

The switch is: result.

Then it has a reply for every combination(though they are not unique because... well--)...

The reply for an incorrect combination goes like this:

First, it sets up the case, for example:

ABC

Then, it gives a message:

"That's not the right combination."

The correct combination goes like this:

Again, it sets up the case:

BED

Then it gives a message:

That's the right combination!

And then it runs a script other than print message:

It opens an object, that object being the desk.

The reason I chose to open it(instead of unlocking it), is because there is no option to unlock an [other than a door] object so it opens`` theobject`` to give it the illusion of unlocking.

Inside the desk, is the attachable laser sight for the snub-nosed revolver.

The attachable laser sight has the feature use/give enabled.

The "use"verb has a script:

Because it's complicated, I'll copy and paste the script code and then try to break it down:

if (Got(revolver)) {
msg ("You have added the attachable laser sight to your revolver!")
RemoveObject (attachable laser sight)
revolver.firearmdamage = "2d6"
}
else if (not Got(revolver)) {
msg ("You can't add the attachable laser sight to your revolver!

You aren't carrying your revolver!")
}

So, first the "use" verb checks whether the player is holding the snub-nosed revolver.

If that goes well, it will remove the attachable laser sight to give it the illusion of it being attached to the snub-nosed revolver.

Then it will change some stats of the snub-nosed revolver.

The original stats:

revolver.firearmdamage = 2d8

With that being changed to:

revolver.firearmdamage = 2d6

To increase accuracy(kinda...)

The else if is:

The verb checks whether the player is not carrying the object;

The object being snub-nosed revolver.

If [the snub-nosed revolver] is not in the inventory of the player, then it simply prints a message:

You can't add the attachable laser sight to your revolver!

You aren't carrying your revolver!

That's the update!

Have a nice day!


UPDATE 2:

I changed the line of code from the use [verb] from the attachable laser sight from:

revolver.firearmdamage = 2d6

To:

revolver.firearmdamage = 2d10

Because (I'm fairly sure) bringing the number down, worsens the revolver.


Because (I'm fairly sure) bringing the number down, worsens the revolver.

2d6 is 2 to 12 damage, average 7. 2d10 is from 2 to 20, average 11.


It seems a little odd to me that a laser sight increases the damage rather than the accuracy.


(POSSIBLY) FINAL UPDATE:

Thanks for all the help!

Quest has really helped me understand code much better.

I'm going to try out some other engines(like Unity).

I may not ever finish this game.


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

Support

Forums