Post new topic    
Liquid Metal Slime
Send private message
Question on NPCs creating other npcs 
 PostMon Jan 25, 2010 5:05 pm
Send private message Reply with quote
I'm at a point in my game where I'd like for a few enemies to have special abilities rather than nothing at all. One idea I had was for a spider to shoot webs at you which can reduce your speed on contact. The problem is that I can't figure out how to get an npc to do something special during an unscripted event. Here's what I got so far:

Code:
   while (get npc id (29) == true) do (
      wait (50)
      if (npc direction (29) == left) then (
         create npc (32,(npc x (29)-1),(npc y (29)))
         set timer (13,3,18,@webdespawn)
      )
      if (npc direction (29) == left && get npc id (32) == -1 ) then (
         create npc (32,(npc x (29)--1),(npc y (29)))
         set timer (13,3,18,@webdespawn)
      )
      if (npc direction (29) == right && get npc id (32) == -1 ) then (
         create npc (32,(npc x (29)+1),(npc y (29)))
         set timer (13,3,18,@webdespawn)
      )
      if (npc direction (29) == up && get npc id (32) == -1 ) then (
         create npc (32,(npc x (29)),(npc y (29)--1))
         set timer (13,3,18,@webdespawn)
      )
      if (npc direction (29) == down && get npc id (32) == -1 ) then (
         create npc (32,(npc x (29)+1),(npc y (29)))
         set timer (13,3,18,@webdespawn)
      )
   )


Am I on the right track with this?
Cornbread Chemist
Liquid Metal Slime
Send private message
 
 PostTue Jan 26, 2010 2:26 am
Send private message Reply with quote
If it makes a difference, this piece of code is in the actual "game" section of my script. The way I saw it was the code would run anytime npc 29 was on the map. Unfortunately, it doesn't seem to work that way.
Cornbread Chemist
Liquid Metal King Slime
Send private message
Re: Question on NPCs creating other npcs 
 PostTue Jan 26, 2010 4:05 am
Send private message Reply with quote
Well I noticed a couple things.
~
The first and biggest being
Code:
get npc id (29) == true

This doesn't do what you think it does.
This should work the way you want it to..
Code:
NPC copy count (29)>>0

~
There's also this,
Code:
create npc (32,(npc x (29)-1)

It needs an extra " - " sign.
~
This is a bit confusing; But I think it's the same problem as before.
Code:
 && get npc id (32) == -1

~
Lastly, the timer... where does it activate? cause that might also cause problems.
Liquid Metal Slime
Send private message
Re: Question on NPCs creating other npcs 
 PostTue Jan 26, 2010 4:40 am
Send private message Reply with quote
Quote:
if (npc direction (29) == left) then (
create npc (32,(npc x (29)-1),(npc y (29)))
set timer (13,3,18,@webdespawn)
)


Wow, can't believe I didn't catch this before. I think I forgot to erase it when I decided I wanted to check npc direction and check to see if the other npc existed as well. Thanks for pointing that and the incorrect signage out.

It spawns the web properly now (and despawns it via the timer), but it doesn't detect collision with the hero. My basic collision script just to check if contact was being made is this:

Code:
   if (hero x (0) == npc x (32) && hero y (0) == npc y (32)) then (
   show textbox (1)
   wait for textbox
   )


Of course, no textbox is being shown, so I'm not sure what to do at this point.
Cornbread Chemist
Metal Slime
Send private message
 
 PostTue Jan 26, 2010 5:04 am
Send private message Reply with quote
My first thought would be to try
[pseudocode]
Code:
if ( (herox == npcx) && (heroy == npcy) ), then

Note the extra parentheses making it clear what the && symbol is trying to decide.

Also, I think I understood the difference before (I don't remember now), but maybe use ",and," instead of "&&"?

If none of these fix the issue, it's probably something about how often the script is being called. Is it a keypress script? If so, you may need "wait for hero" commands to occur before this if check, so that it waits for the hero to complete his step...
I am Srime
Liquid Metal King Slime
Send private message
 
 PostTue Jan 26, 2010 1:33 pm
Send private message Reply with quote
Msw makes a good point. It's good practice keep things separate in a visible way. However, that comma at the end of his if statement is just plain bad form.

There's nothing really wrong with this script. My only thoughts are that, either there's something else in your script preventing this from working, you aren't able to step on the web (via step on npcs or suspended obstruction), or maybe you have more then 1 spider web on the map.

If you have more then 1 web, then this wouldn't work, because you're using a npc ID were you should be using an npc reference, which then only refers to the first copy of the npc.

A fix to this would look something like this.
Code:
if ( Get NPC ID (NPC at pixel (hero pixel x (me)+10,hero pixel y (me)+10, 0) ) == 32)


I'll explain what this script does a little. First, it checks the 1st layer of npc touching the middle pixel of the hero. Walkabouts have 20 pixels across and down and "hero pixel x/y" gives you the top right corner, so it adds 10 to make it check the middle instead of the upper right corner. Next, it switches npc reference, to npc ID with the get npc ID command. Then, it checks to see if the ID is 32. Hope this works.
Metal Slime
Send private message
 
 PostTue Jan 26, 2010 4:33 pm
Send private message Reply with quote
Ouch, bad form huh? What's wrong with a little comma abuse? I remember thinking from before that Hamsterspeak needed that comma for the word "then" to be on the same line, but I guess not.

Spoonweaver's script could get into trouble if there is more than one web, because there could be more than one npc at the pixel. I don't think that that will be an easy scenario to work out, but first MBS, do you indeed have the possibility of more than web existing at once?
I am Srime
Super Slime
Send private message
 
 PostTue Jan 26, 2010 5:06 pm
Send private message Reply with quote
Any, two, separate, tokens, in, HamsterSpeak, can, be, separated, by, linebreaks, or, commas.

You
can
make
your
script
really
hard
to
read.
Mega Tact v1.1
Super Penguin Chef
Wizard Blocks
Liquid Metal King Slime
Send private message
 
 PostTue Jan 26, 2010 5:19 pm
Send private message Reply with quote
also, you can put a bunch of commas in a row ,,,,,,,,,,,, and they will be treated as just one comma. You can put a comma at the end of the line and it will be totally ignored.

I rank that high (but not highest) in my list of crappy decisions that I made when designing the hamsterspeak language.
Liquid Metal King Slime
Send private message
 
 PostTue Jan 26, 2010 5:55 pm
Send private message Reply with quote
@commas:
I don't think the way they're set up is bad at all James. Good work in fact. I was merely pointing out that a comma in between If() and then() isn't correct.
Or is it? can you separate If() and then()? I've never tried.....
No big deal either way I guess.

Quote:
Spoonweaver's script could get into trouble if there is more than one web, because there could be more than one npc at the pixel. I don't think that that will be an easy scenario to work out, but first MBS, do you indeed have the possibility of more than web existing at once?


This is true. And I do have a way to address it.
I use a For command to go through the "get count" of the pixel location. Though, I suspected the slight chance of this happening wouldn't mess with game play that much.

It would go kinda like this.

Code:
variable (layercount)
for(layercount,0,NPC at pixel (hero pixel x (me)+10,hero pixel y (me)+10, get count),1) do , begin
if ( Get NPC ID (NPC at pixel (hero pixel x (me)+10,hero pixel y (me)+10, layercount) ) == 32) then , begin

#-----web scipt HERE----

end
end
Metal Slime
Send private message
 
 PostTue Jan 26, 2010 8:08 pm
Send private message Reply with quote
I think I thought the comma was needed because I remember taking to heart that Hspeak treated blank space as if it wasn't there, so if I wanted to actually separate the word "then" from the end parenthesis, I needed a comma between them. Of course this doesn't make much sense, because an end parenthesis must be a special character that designates a completion of something, and I certainly didn't use commas with things like equals signs
Code:
if ( 2+3, ==, infinity), then


I will note, however, that the comma before the "then" does work just fine. I have 14621 lines of proof in one game, haha
I am Srime
Super Slime
Send private message
 
 PostTue Jan 26, 2010 8:11 pm
Send private message Reply with quote
Remember that parentheses are just a special way of saying "begin" and "end." This works just the same:

Code:
if, begin, 2 + 3 == infinity, end, then


With that in mind, it makes sense that an extra comma after your parenthesis doesn't matter.
Mega Tact v1.1
Super Penguin Chef
Wizard Blocks
Display posts from previous: