Post new topic    
Page «  1, 2, 3, 4, 5, 6  »
Slime Knight
Send private message
 
 PostMon Dec 22, 2014 2:43 am
Send private message Reply with quote
Just updating, after doing some adjusting, and re-adjusting of my scripts, I've made a bit of progress in that, I think I've done away with the infinite loops. So thank you very much for the help with that! That's something it would have taken me forever to figure out.

So, the scripts don't freeze the game, however I still haven't worked it out so that while tag 12 is on, pressing space fires a bullet. still working on it.

I have read through the other thread about the bullets not originating from the hero. I'm not there yet, but I was wondering if I would encounter this problem, as each map in my game is 16x10, thus requiring no scrolling. I guess I'll see when (if) I get there.

I took some time way from the shooting scripts to work on some other things in the game, so it wasn't a totally wasted day! The check for the ending, as well as the death scripts are working well. Good stuff

So, Thank you again for the help thus far. I'll continue to post progress and (far more likely!) problems.
Metal King Slime
Send private message
 
 PostMon Dec 22, 2014 3:27 am
Send private message Reply with quote
Are you still doing this?
Code:
plotscript, shootabullet, begin
variable(sl, isshooting, bullet)
    if(keyval(key:space)>>1) then(
        if(isShooting <> 0) then(
          isShooting := 1
            if(hero direction (me)== right) then(
       bullet := create rect (2, 2, 2)
       put slice (bullet, hero pixel x, hero pixel y)
            set slice velocity x (bullet, 20, 10)
            set slice velocity y (bullet, 0, 10) 
       (play sound (21,false,false)) 
       delete item (item:shell, 1)
            isShooting := 0
            exit script
          ) )
etc...


it's hard to tell, but I think the reason it's not working is
[code]
if(isShooting <> 0) then(
isShooting := 1
...

[/]

You're essentially asking "Does IsShooting NOT Equal 0? If so, set it to 1, aka Non-Zero!". I think you mean to ask "Are we already shooting? If so, don't do anything. If we aren't, then we're shooting NOW, block subsequent shots and let's make that shot happen."
Slime Knight
Send private message
 
 PostMon Dec 22, 2014 4:26 am
Send private message Reply with quote
Awesome, I did actually fiddle with that bit of coding (I think I may ripped it from Sheamkennedy's code, sorry dude) But I honestly can't remember if I was still having loop issues when I did, so I'll try it again. Thanks!
Slime Knight
Send private message
 
 PostMon Dec 22, 2014 9:26 pm
Send private message Reply with quote
The daily conundrum perpetuates!

Kamina The good news:

I have made some progress, in that I have actually fired a few bullets. I tweaked the scripts until I found a way to load what I want without causing an endless loop, or conflicting scripts.

Also, I've got it so that the script runs when you have ammo, and stops when you run out.

:(The Bad news, well, not necessarily bad, just another challenge to overcome:
I've tried running this script as a map autorun, and an each-step. This allowed me to fire bullets, but only when first entering a new map (autorun) or while I was stepping (each-step).
If I took a step while holding Space, a shot fired, if I walked to a new tile, waited a second, then hit space, nothing happened. I'm a little confused by this.

However, I'll count all this as progress given the trouble I've been having.

Also, I haven't had any issues with my bullets not originating from my hero, so that's good! However, when I shoot while running right or left, they seem to stop short.

Here are the latest code strings I'm using (the Steps2 script is an each step script)

Code:

plotscript,steps2, begin
play sound (20, false, false),
(setup score)
   if ((inventory (item:shell))
) then (if
   (keyval (key:space)>>0)
then
   (shootabullet)
else if(item count in slot (0)<<1) then
 (play sound (2,false,false), show map)
)
   while (lever >5) do (winner)
end

plotscript, shootabullet, begin
variable(sl, isshooting, bullet)


            if(hero direction (me)== right) then(
       bullet := create rect (2, 2, 2)
       put slice (bullet, hero pixel x, hero pixel y)
            set slice velocity x (bullet, 20, 5)
            set slice velocity y (bullet, 0, 10) 
       (play sound (21,false,false)) 
       delete item (item:shell, 1)
wait (9)
free slice (bullet)
            exit script
          ) else
            if #etc for each direction...
Metal King Slime
Send private message
 
 PostMon Dec 22, 2014 10:25 pm
Send private message Reply with quote
Okay, I think that's your problem. A Map-Autorun script doesn't work the way you seem to think it does. It only runs automatically when you first enter that map, so it only checks all those conditionals once, and if you're not doing whatever in that particular 18th of a second, you're out of luck.

Your each-step script works the way it does because everytime you take a step, it asks all your questions again and this time some of the answers are "yes".

You obviously want to ask those questions more often than you're doing now. That's what a While Loop is for. I think that's what you're trying to accomplish with your

Code:
while (Lever >5) do (Winner)


but like everything else, it's only checking that once every time you enter a map, and once every time you take a step.

While is a lot like if, only with a twist. If While is true, it keeps checking and doing that thing until it's not true, where if only checks it once. Let's say you have a GlobalVariable called Count...

Code:

if (Count << 10)
then (
        CreateNPC (0)
        increment (Count,1)
       )


You run that script, and it will create a single NPC. Run it ten times, and it won't do anything, because Count will be 10 or higher. Compare to:

Code:


while (Count << 10)
do (
     createNPC (0)
     increment (Count,1)
     )



If you run this code, it will create ten NPCs in the blink of an eye. Run it again and it won't do anything, because Count will be 10 or higher. Run it after you've run the If version a few times, and it'll still create NPCs, but only until that number is ten.

Now if you run THIS code, you'll see some serious shit.

Code:

while (True) #This condition is always true. This can be dangerous, but also fun.
do (
     if (KeyVal (Key:Space) >> 1)
     then (
             CreateNPC (0)
             )
     
     #Wait (1) is very important
     #Without it, this particular while loop will be stuck in a permanent
     #loop because it's condition is always true. Wait (1) gives a tick
     #for the screen to update and the player to get to hit buttons.
      wait (1)
      )


Once you run this script, everytime you hit Space it will create an NPC, and because of the way it's set up, you'll never be able to stop it. That can be a good or a bad thing, depending on what you're trying to do. You'll notice too, that we didn't need a wait (1) in that earlier while loop. That's because it makes its own conditional untrue as it goes, once Count is ten the while loop ends and you're ten NPCs richer in the blink of an eye. (You might also notice that I forget to say where it should create the NPC, if you actually compile this code.)
Liquid Metal King Slime
Send private message
 
 PostMon Dec 22, 2014 10:37 pm
Send private message Reply with quote
Post screenshots!
Slime Knight
Send private message
 
 PostMon Dec 22, 2014 11:43 pm
Send private message Reply with quote
Holy Mustard!

Thanks Gizmog! This is why I continue to post here... left to my own devices I make endless amounts of stupid mistakes!

I put everything I wanted to happen into a single While loop (with a wait(1) command!) and as far as I can tell, things seem to be working pretty much how I had hoped!

I'm running around, and shooting like nobody's business. Now I shall attempt to finish things up with the Slice Collision codes you mentioned earlier.

Again thank you so much! And a word of warning... expect further dumb questions and problems from me...
Metal King Slime
Send private message
 
 PostTue Dec 23, 2014 12:44 am
Send private message Reply with quote
No problem, that's what we're here for!
Slime Knight
Send private message
 
 PostTue Dec 23, 2014 3:03 am
Send private message Reply with quote
I'm now moving on to working on hot detection. I found the following code in the dictionary

slice collide (handle1, handle2)

This seems like it may be useful, however, I must now further disclose my ignorance regarding slices. I fooled around a little bit with slice collections. But I am unsure as to what each slice handle is, and how to identify a slice in a collection. Yes, I know these are incredibly elementary things.

the scripts I'm using with slices are:

Code:

plotscript, shootabullet, begin
variable(sl, isshooting)


            if(hero direction (me)== right) then(
       bullet := create rect (2, 2, 2)
       put slice (bullet, hero pixel x, hero pixel y)
            set slice velocity x (bullet, 15, 20)
            set slice velocity y (bullet, 0, 10) 
       (play sound (21,false,false)) 
       delete item (item:shell, 1)
wait (9)
free slice (bullet)

And
Code:

   variable(hero, sl, picsl, picnum, npid )

   npid:= 8
   picnum:= 1 #the sprite I want to "hit" with the bullet


   sl := get NPC slice(  npid  )
   picsl := lookup slice(sl:walkabout sprite component, sl)
   replace hero sprite(picsl, picnum)


the first is my projectile script where a rectangle is created and Identified as "bullet." I have "Bullet" set as Global variable, but it is undefined anywhere except in the "ShootABullet" script.

The next script is the "walktall" script. I'm using it to make the enemy monster larger than a standard NPC, it uses hero sprites. I have another Global Variable "monster" that I have not defined anywhere in my script.

I'm not sure how to define the Monster variable, or if it is even something I need to do. I imagine I can identify it by the slice its using (it's the only thing in Slice Collection 1)

Also, I'm not sure if that is the slice I would use, or if I would want to use the slice of the NPC that the walktall script is replacing.

So, that's where I am. I'm trying to make it so If you hit the monster with a bullet, it disappears. poof. Sounds easy, but these slices are such a strange and nebulous concept to me....
Metal King Slime
Send private message
 
 PostTue Dec 23, 2014 4:08 am
Send private message Reply with quote
A slice handle is basically just the number that the engine uses to refer to that particular slice, kinda like how you can say Hero (Me) to refer to the first hero or whatever. There's a lot of different ways to get a particular slice handle. As you've seen, most of the ways you can load or create a slice return their handle. That's why you say

Code:
bullet := createrect (2,2,2)


rather than just

Code:
createrect (2,2,2)


When you say "CreateRect" you're Creating a Rectangle, but the script is also answering what the number of that rectangle is. We store that number in the variable Bullet, and once you've got those digits, you can call it whenever you like. There's other ways to get that number, too.

I've never used walktall, so I don't know EXACTLY how it works, but let's take a look at what we do know: It replaces a sprite with a bigger sprite. ReplaceHeroSprite's first argument is a SliceHandle. We got a ReplaceHeroSprite in the script, and it's first argument is PicSl. So, let's see what happens if Bullet collides with PicSL. You might need to replace PicSl with a global variable.

You might also notice that lookupslice, and how you can use Slice Lookup codes (Of which you can define your own in the editor) to pick up a particular piece of data. For instance, in this script PicSl is the attached Walkabout Sprite Component of a certain NPC Slice.

Ctrl+F4 will show you all the slices and their handles, though I wouldn't recommend trying to write a script that way. It does, however, give you a better idea of how everything's put together.
Slime Knight
Send private message
 
 PostWed Dec 24, 2014 12:06 am
Send private message Reply with quote
After some tests, and checking out the ctrl+f4 slice debug menu, made a little progress.

I've tried the scripts using both the slice handle numbers that I got from the ctrl+f4 menu, these were simply 1, and 2. I also (as an experiment) tried it with the slices' lookup codes from my .hsi file. I get the same results either way.

It now works so that when I hit space, it fires a bullet, and deletes one ammo.

When I'm in a room with a monster, and I hit space, a bullet fires, and the monster disappears regardless of whether or not I hit him, or am even aiming in his direction.

Code:
plotscript, hitdetect,begin

if (slice collide (sli:bullet,sli:monster) ==true)
then(set tag (28, off) wait (1))
else (show map)

end


I also tried the above code with (>>0) as opposed to (==true) with the same result. I also tried it in a while-loop, but got an error telling me that "bullet" was not there, or had already been deleted.

Code:

plotscript, shootabullet2, begin
variable(sl, isshooting)


            if(hero direction (me)== right) then(
       bullet := create rect (2, 2, 2)
       put slice (bullet, hero pixel x, hero pixel y)
            set slice velocity x (bullet, 15, 30)
            set slice velocity y (bullet, 0, 30) 
       (play sound (21,false,false)) 
       delete item (item:shell, 1)
wait (3)
(hitdetect)

#etc...


So that's the tale of the day. A bit of progress (I was stuck with a half dozen different errors earlier, but got past them) so I figured I would post about this to see if anyone had any thoughts, or if simply typing out my issues would kickstart my brain.

I'm wondering if I'm somehow using an incorrect slice handle, so that when I fire the bullet, the bullet slice is maybe colliding with it rather than the intended monster slice...
Metal King Slime
Send private message
 
 PostWed Dec 24, 2014 5:19 am
Send private message Reply with quote
A lookup code, I should mention, isn't a slice handle. It's a means to get a slice handle via LookUpSlice. Open up your .hsi, and look at the entry for sli:bullet and sli:monster. See that number to the left? That's what you're actually saying when you say

Code:
if (slicecollide (sli:bullet,sli:monster))


it's translating to something like...

Code:
if (slicecollide (3,6))


You could type it out that way, if you wanted to. But it'd be really hard to read, which is why we do the sli:bullet stuff. There's a big difference between a slice lookup code and a slice handle. A slice handle is a unique identifier for a particular slice: There's only one slice with each handle. A slice lookup code is different. Every slice you have could have the same look-up code, but they'd each have a different handle.

What LookupSlice does is finds the handle of a slice that you've assigned that lookup code to. So when you say

Code:
LookUpSlice (sli:Bullet)
you're getting the handle of the first slice that has the lookupcode sli:Bullet. If there were more than one slice with that look-up code you might want to narrow it down a little and there's ways to do that, but no need to go into them yet. For right now, let's look at the part of the script that is working correctly and figure out why that is.

Code:

plotscript, shootabullet2, begin
variable(sl, isshooting)


     if(hero direction (me)== right) then(
       
       #This creates a rectangle, and records its unique handle number to
       #the variable named Bullet
       bullet := create rect (2, 2, 2)
 
       #These commands work correctly, so you know that bullet is the
       #right slice handle and that you're using it correctly,
       #so you don't need to look anything up.
       put slice (bullet, hero pixel x, hero pixel y)
       set slice velocity x (bullet, 15, 30)
       set slice velocity y (bullet, 0, 30) 

       #Sounds are always good!
       play sound (21,false,false)
       delete item (item:shell, 1)
       
       #I still don't know what this is trying to accomplish.
       #wait (3)

       #and you probably shouldn't tie your hit detection to your shot
       #like this. It should be in your while loop seperately. Otherwise,
       #You're only checking if the shot hits once... in the same tick that
       #you fired it!
       hitdetect

#etc...



Now, let's look at the part of the script that doesn't work

Code:

plotscript, hitdetect,begin

#We're using sli:bullet here, and that doesn't work because it's
#a look-up code, not a slice handle. Apparently there is a slice whose
#handle is the same number as our look-up code, which is interesting
#but doesn't actually help us any.

#Bullet did work when we used it in those other scripts, so I would change
#sli:bullet to Bullet and see what happens...

#Except sli:monster is a lookup code and not a handle also! To find a slice
#that has that LookUpCode, you should use LookUpSlice (sli:monster)
#instead

if (slice collide (sli:bullet,sli:monster) ==true)

#I assume this destroys the monster, seting the tag is a good way to
#do that.
then (
        set tag (28, off)

       #All this wait is gonna do is make things jerky.
       #If you're worried about the while loop thing, it's already got a wait
       #in it.

        wait (1)
        )

#Not to nag again, but you don't need a show map unless you did a
#showbackdrop somewhere else earlier, and even if you did, you
#wouldn't need to undo it every tick that a shot isn't hitting its target.
#Don't forget that else conditionals are optional
else (show map)

end
Slime Knight
Send private message
 
 PostFri Dec 26, 2014 1:07 am
Send private message Reply with quote
So, after the better part of a week of frustration, stupid questions, and bad coding, I think I finally actually have it so that..

push space,
fire bullet,
remove bullet from inventory,
bullet hits bad guy,
bad guy stops,
sound plays,
bad guy dies,
player gets points.

With no errors! I've never put much stock into the holidays, but from this point forward, I will be a believer in Christmas miracles! Hahaha. Angel

Thanks to everyone who checked out this thread, and replied. And a special thanks to Gizmog, for your help and patience with me throughout my endeavor.

There was one question I will ask though. Do the Slice dissolve commands from the dictionary work with the stable OHR, or just with the nightly's?

Thanks again Smile hopefully I'll have something to show for all this grief soon
Metal King Slime
Send private message
 
 PostFri Dec 26, 2014 5:29 am
Send private message Reply with quote
Sure, no problem. Glad to hear it's workin out. Ths SliceDissolve commands only work in the nightly, as far as I know.
Slime Knight
Send private message
 
 PostSat Jan 03, 2015 2:57 am
Send private message Reply with quote
I encountered a little curiosity while playing with some scripts. I got the idea to add another element to the game I've been making.

It is a simple game which involves avoiding a monster and hitting switches, when you hit 6 switches, you win. I got the thought to have it so when you hit all the switches, the game restarts and the player can just repeat the process for a high score.

I wanted to add the element of increased difficulty. I set it so that when you hit all 6 switches, tag 29 is turned on. Tag 29 is set to change the movement speed of the monster NPC from 2 to 4, making the second run through a bit more challenging.

This seems to almost work, however, after tag 29 is set on the monster NPC only steps 1 tile from his point of origin, then stops (still doing his walk animation) I can tell that he takes this one step at an increased speed, so that part is working. I'm just wondering if anyone had any thoughts on this.

Below is the snippet of code being used. Note, I'm using the walktall "embiggen NPC" scripts in case this makes a difference.
Code:
plotscript, chase, begin
set tag (28,on)
play sound (18, true,true)

   variable(hero, sl, picsl, picnum, npid)
   npid:= 8
   picnum:= 1

   sl := get NPC slice(  npid  )
   picsl :=lookup slice(sl:walkabout sprite component, sl)
   replace hero sprite(picsl, picnum)

while (lever<6)
do( (hitdetect)
   if (check tag (29)==on)
   then (set npc speed (8,4))
#etc...


Any thoughts are welcome. Thanks! Smile
Display posts from previous:
Page «  1, 2, 3, 4, 5, 6  »