Post new topic    
Liquid Metal Slime
Send private message
Issue with String Clearing on Movement 
 PostFri May 09, 2014 3:19 pm
Send private message Reply with quote
EDIT: I apologize in advance for the lack of indentation on these scripts. I had a big issue with posting them on here for some reason. Every time I went to submit the thread, it would erase most of the script. That's why I had to split them up.

Hey guys,

I have a script that displays a string for 15 ticks and then clears itself automatically. It allows hero movement while this is taking place.

Quote:
plotscript,test,begin
if (check tag (302)) then (
wait (15))
set tag (302,on)
play sound (35,false)
variable (lt)
testslice:= load slice collection (5)
lt := random (1,10)
if (lt >= 1 && lt <6>= 7 && lt <8>= 9 && lt <= 10) then (
$10 = "z"
)
set slice text (lookupslice (sli:testtext),10)
$10 = ""
wait (15)
free slice (testslice)
set tag (302,off)
end


This works as intended, with the exception of one scenario. If I open up the main menu and then close it before running the string script, then the string will clear if the hero moves around rather than by the script itself.

It will clear by the script properly if you stand still for 15 ticks, but will prematurely clear if you move the hero before that time. Do you have any idea what might be causing this behavior? Here is the menu script, for reference:
Cornbread Chemist
Liquid Metal Slime
Send private message
 
 PostFri May 09, 2014 3:21 pm
Send private message Reply with quote
Quote:
plotscript,menu,begin
if (string is visible (0)) then (
set tag (298,on)
clear string (0)
clear string (1)
)
if (current text box == -1) then (
free slice (menuslice)
if (hero is walking (me) == false) then (
if (keyval(key:esc) > 1 || keyval(key:filteredalt) > 1) then (
menuslice := load slice collection (4)
flvl := get hero level (find hero(hero:Fred))
fmc := get hero stat (find hero(hero:Fred),stat:Mastery)
fmm := get hero stat (find hero(hero:Fred),stat:Mastery,maximum stat)
fhc := get hero stat (find hero(hero:fred),stat:Health)
fhm := get hero stat (find hero(hero:fred),stat:Health,maximum stat)
fexp := experience to next level (find hero(hero:Fred))
pmon := party money
$10 = ""
append number (10,flvl)
set slice text (lookup slice(sli:fredlevel,menuslice),10)
$10 = ""
append number (10,fmc)
set slice text (lookupslice (sli:fredcurms,menuslice),10)
$10 = ""
append number (10,fhc)
set slice text (lookupslice (sli:fredcurhp,menuslice),10)
$10 = ""
append number (10,fexp)
set slice text (lookupslice (sli:fredxptolvl,menuslice),10)
$10 = ""
append number (10,fmm)
set slice text (lookupslice (sli:fredmaxms,menuslice),10)
$10 = ""
append number (10,fhm)
set slice text (lookupslice (sli:fredmaxhp,menuslice),10)
$10 = ""
append number (10,pmon)
set slice text (lookupslice(sli:coins,menuslice),10)
$10 = ""
open menu (0)
)
)
)
end

Cornbread Chemist
Liquid Metal King Slime
Send private message
 
 PostFri May 09, 2014 4:24 pm
Send private message Reply with quote
Sometimes the forum has problems with the > and < symbols in comparison operators. Sometimes using pastebin is easier.

I am going to suggest a different approach. This is a perfect problem to solve with timers. Here I how I would do it:

Code:

global variable(57, info sl)

plotscript, show info string, begin
  load info string
  set timer(1, 0, 15, @remove info string)
end

script, load info string, begin
  remove info string # prevents loading the collection twice
  info sl := load slice collection(5)
  $10 = "z"
  set slice text(lookupslice(sli:testtext), 10)
  $10 = ""
end

script, remove info string, begin
  if(info sl) then(
    free slice(info sl)
    info sl := 0
  )
end


Let me know if that makes sense.
Liquid Metal Slime
Send private message
 
 PostFri May 09, 2014 5:27 pm
Send private message Reply with quote
Thanks. Your method is way more efficient than my original one.

Unfortunately, the original issue still remains. If it helps, I've noticed that it will clear any string from the screen, not necessarily the one called by the script I mentioned above.
Cornbread Chemist
Liquid Metal King Slime
Send private message
 
 PostFri May 09, 2014 5:57 pm
Send private message Reply with quote
Hmm... that is strange.

So the slice collection that contains the text is disappearing whenever you take a step. Try pressing F8 and browsing the Slice tree. Is the text slice completely gone? or is it still there, but moved somewhere off-screen?

Does it vanish as soon as you press an arrow key to move the hero? (in that case, our first suspect is the on key pressed script)

Or does it vanish after you complete a step? (in that case, our suspect is the each-step script)
Liquid Metal Slime
Send private message
 
 PostFri May 09, 2014 6:43 pm
Send private message Reply with quote
I checked the slice tree but I honestly don't know what I'm looking for. I don't think I see anything that has to do with the slice on there though, but I may be wrong.

The vanish definitely happens as soon as you hit the arrow key as opposed to completing the step. The on key press script is the menu script that I mentioned above.
Cornbread Chemist
Liquid Metal King Slime
Send private message
 
 PostFri May 09, 2014 8:00 pm
Send private message Reply with quote
Very peculiar.

Your on keypress script doesn't seem do do anything that would free already loaded slices, other than menuslice.

How many places in all your scripts do you use the "free slice" command.
Liquid Metal Slime
Send private message
 
 PostFri May 09, 2014 8:20 pm
Send private message Reply with quote
Figured it out! This

Code:
if (current text box == -1) then (
free slice (menuslice)


Was the problem. I remember putting it in for some reason, but I can't figure out why now. Everything seems to work okay without it, and most importantly, the strings aren't being prematurely cleared anymore.

Thanks for the help!
Cornbread Chemist
Metal King Slime
Send private message
 
 PostSat May 10, 2014 1:03 am
Send private message Reply with quote
When posting scripts tick "Disable HTML in this post" and it'll stop it from tripping up on the angle brackets.
Liquid Metal Slime
Send private message
 
 PostSat May 10, 2014 1:15 am
Send private message Reply with quote
TMC wrote:
When posting scripts tick "Disable HTML in this post" and it'll stop it from tripping up on the angle brackets.


Nice! I'll remember that next time.
Cornbread Chemist
Display posts from previous: