[SOLVED] Clear specific text strings?

I want my game to delete some specific lines and overwrite them right after. Clearing the screen is not an option, because that would mean entering new rooms to simulate that overwriting and breaking some scripts running on the background :(

I'll show you a quick example of what I want:

msg ("Please login to start:")
msg ("<br>")
msg ("U S E R N A M E :")
get input {
// check input and see if it is correct goes here, no problem with that
}
// mysterious script that deletes the text shown when 'msg ("U S E R N A M E :") was executed goes here, this is what I need and don't know how to do
msg ("P A S S W O R D :")
// the password msg needs to go at the same line username did

I think I explained it more or less well, but tell me if you have any problems understanding ^^


I'm probably no understanding what you want... but there's:

ClearScreen ( http://docs.textadventures.co.uk/quest/functions/corelibrary/clearscreen.html )

(or, did you want to delete specific lines: current, above, or below? I'm not sure if or how this would/could be done in quest)

and then you can concatenate, if you want username+password to all be on same line:

(adjust it as you want, as I've no idea what you want, lol)

(I just chose to use the 'game' Game Object for the Object, but you can use whatever Object, having whatever String Attribute, you want)

msg ("Please login to start:<br>U S E R N A M E :")
get input {
  game.username_string_attribute = result
  if (game.username_string_attribute = "WHATEVER") {
    ClearScreen
    msg ("U S E R N A M E : " + game.username_string_sttribute + ", P A S S W O R D : ")
    get input {
      game.password_string_attribute = result
      if (game.password_string_attribute = "WHATEVER") {
        ClearScreen
        msg ("U S E R N A M E : " + game.username_string_attribute + ", P A S S W O R D : " + game.password_string_attribute + "<BR>Logging in, please wait...")
        // whatever you want to do now...
      } else {
        msg ("Wrong input, try again.")
        wait {
          ClearScreen
          // loop/call/do this scripting block again
        }
      }
    }
  } else {
    msg ("Wrong input, try again.")
    wait {
      ClearScreen
      // loop/call/do this scripting block again
    }
  }
}

if you want to see some examples, or at least ideas on things, you can take a look at this:

http://textadventures.co.uk/forum/samples/topic/4988/character-creation-crude-code-and-sample-game


This might work:

		msg ("Please login to start:")
		section = StartNewOutputSection()
		msg ("U S E R N A M E :")
		EndOutputSection(section)
		get input {
			HideOutputSection(section)
			name = result
			section = StartNewOutputSection()
			msg ("P A S S W O R D :")
			EndOutputSection(section)
			get input {
				HideOutputSection(section)
				password = result
			}
		}

If you want more advanced control, you can output actual HTML (divs with IDs, etc), and then use jquery JavaScript commands to style, hide, animate, etc them.


Hi! Sorry for the late response.

I may be a bit (or too) perfectionist with my code and how the "visuals" are rendered in the screen. I know that the feature I want to add is very hard and specific, so don't worry :p

Still, thank you very much for your help... and for that beautiful character creation system I will use in the future, crediting you, of course!

I will do some research on js and notify you if I find a way to do exactly what I want!


Jay, we replied at the same time!

I'm going to try that. Thanks ^^/


I'm a bit of perfectionist myself. Not that I ever achieve perfection, mind you, but I have no problem spending time on the little details that add up to a larger impression. Keep pushing for your vision. :) We'll help make it happen.


the character creation code is old, for some reason during that time, it never occurred to me (my mind failed) that I can use only a few dynamic Functions via parameters to handle all of those tons of redundent Functions you see in that link to my old character creation code. I've improved upon it, but am still working on trying to make it better (wanna-be perfectionist too, argh). But, I still like linking to it, as the first Functions give some good examples of various things you can do with the handling/manipulation of input, as at the very least ideas for people, and the redundent Functions gives examples of what (and how) you can do with List and/or Dictionary Attributes. Right now, I'm trying to use Objects (Object Oriented Design) instead of Functions/scripting, as at the very least, they're more organized and easier to edit/scale, though this Object Oriented Design is still quite a bit foreign to my brain. Also, my brain just has a hard time with so many files/Objects/Object Types, the most basic aspect of Object Oriented design, lol-argh.


@ anyone who might be able to answer this in terms of generally only of course, if that's even possible, of course:

Is using Objects and their Script (+ Delegates) Attributes better than using Functions with Quest's programming? Do Objects+Script Attributes+Delegates require more overhead (activation records/memory/space/operations/etc) than do Functions, or is it vice versa, and if so, is it significant, or is the organizational and editibility/scalability of Objects+Scripts+Delegates outweigh whatever more overhead they have if they do, over using Functions? Also, how about in terms of recursion, are Objects+Scripts+Delegates worse recursion'ing or Functions, or are they they same? I still need to wrap my head around understanding and successfully coding/doing Data Management structures/systems (trees, dictionaries, heaps, queues, maps/whatever it's called, etc), so that's completely out of the question at the moment, though if/when I finally learn this stuff, it'll greatly make the coding more efficient with handling Object Ortiented Design. But for now, I'll likely have to use basic 'helper-like' scripting/Functions for handling the actions/stuff to do with the Objects or from one action/Object to the next, etc...

As there's quest's surface-user-level programming, on top of quest's actual underneath programming (I mean it's source/developmental code that makes quest work/be quest: connects quest's surface code with the computer system code), on top of the computer system code, as well.


As with most things, you can't generally say one is better than the other. If they could both be used for the same thing and one was clearly better than the other, then there would be no need to implement both.

Functions are simple bits of functionality, with an input and output (though, sadly, they can have side effects by reaching out to global objects). If you just need some functionality, and you don't need to worry about state associated with the function, then a function is all you need.

Objects encapsulate both functionality and data. A script attribute on an object is just a function (though the way they are invoked in Quest makes this less clear than a language like C++ of JavaScript, where the syntax is the same, just with a binding to an object (e.g. object->someFunction(a, b) ). Script attributes on objects are handy when you want to call the same function on different objects by the same name but have different behavior. (In computer programming parlance, this is called "polymorphism", where the same call on different objects has different behavior.)

So it comes down to what you want to do. Creating an object with a script attribute when all you need is a bit of functionality is overkill. Trying to use functions for functionality+data is possible (e.g. you can always pass in the object data you want to operate on), but I can't even think of way to create polymorphism without binding a function to an object somehow. And using "if" statements to simulate polymorphism (e.g. "if it's object A, do this, else if it's object B do that, else...") makes for tightly coupled, brittle code.

I wouldn't even bother worrying about overhead unless you have a specific case where performance becomes a problem. The level of scripting that is typically done in a text adventure game isn't going to do much to tax a computer either way. (I ran into performance problems myself with the path finding code I wrote, but that's the only time I ever had that sort of problem.)

I hope that helps!


thanks Jay, I was just curious with quest's coding structure on these things as I'm getting into learning using Data Structures and design/operation efficiency of them (logorithmic base 2, logorithmic base N, Ns, N^2s, etc), I was wondering with quest if generally using Objects+Script Attributes+Delagates and trees/queues/etc vs scripting/Functions, if there was any clear differences, though I should be more aware, as, as you said, if there was a clearly better method, then there'd just be that method. And (now) obviously your point about if you only need an operation, then use Functions (+Parameters), if you need operations+data storage, then use Objects(+Script Attributes + Delegates).


And in my classes we never covered (probably will get into it in more higher/advanced classes later on) in general the Activation Records (overhead/etc) of Functions vs that of Objects, so tried asking about it here, to just learn and understand a bit more on this type of stuff. Obviously, it depends on design/needs, but I was just trying to understand more of this aspect of programming in data management/limiting space/memory, and operational efficiencies.


is there any differences in regards with recursion, are Object's Script Attributes+Delegates recursive usage the same as Function (+Parameters, of course) recursive usage?


As far as overhead goes, for a function, it has to look up the function by name in a global space. For the script of an object, assuming you have the object, it's just a name lookup in the attributes of the object. If you don't have the object yet, then you have to look up the object by name. However, unless you're doing high performance programming, I wouldn't worry about it. According to Donald Knuth, "The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times; premature optimization is the root of all evil (or at least most of it) in programming." For what you're asking about, if there's a difference, it would be on the order of milliseconds or microseconds, which won't even be noticeable to a player. The only way you could know for sure would be to measure it. If you really wish to know, that's the only way to find out - write some code that executes a function call and then an object script call millions of times to make the time measurable, and then measure it!

There is no difference in how you do recursion with the two, beyond the differences involved in making the calls to begin with.


thanks jay. I know I'm asking a lot of generalized questions which don't have answers (generalized nor specific), but I'm doing so, just to try to understand more about the inner workings of programming. Though, I'm definately falling prey exactly what Donald Knuth is talking about laughs, but for me, it's about just trying to get a better sense/understanding of the inner workings that're going on, and not about the actual specific/definitiveness of the efficiencies/etc, just trying to learn the whats, hows, and whys, of stuff. So, thanks for answering these poor unanswerable questions of mine, your answers, are really helpful for me in understanding more about programming, though I still get a lot of it mixed up, but that'll come later when I really start to understand programming... hopefully, laughs (I'll probably still get a lot of stuff confused... knowing me... lol).


I am aware that most of this is indeed in terms of nanoseconds (and that it's too generalized to give answers: as you mention, you need to actually have a high perforance stop watch and actually time the program/code execution), as we're not likely to be working with 'big data' or a really huge-complex program, nor with embedded/critical systems, where the inefficiences/memory/space do become noticeable and/or dire with many embedded/critcal systems and/or their limitations of memory/space (due to cost and/or actual physical space available for the hardware and/or whatever else), as it seems most people do software, and not hardware and/or embedded/critical systems, unless you're more into physical engineering and thus you're more interested in hardware/embeded systems and the archecture of computer/circuitry than just high level software programming.

I am interested in efficiency, as my brain likes procedural, I find it fun trying to come up with the most efficient code I can, though I know it's not that hard to do so, meh. At least for now anyways, while I'm still trying to train my brain in more abstract thinking with OOP/OOD and Data Structures. Working with Assembly was a lot of fun for me. Though, my brain works more on the generalized/theoretical/big/macro outlook, than on specfic details / micro... not a good thing for being a programmer, I know... hopefully that'll eventually come with time, when I'm actually interested in actually clocking it, seeing if something is more or less effecient than other code designs. So that's why I'm still asking a lot of useless unanaswerable questions, I'm just trying to grasp stuff in the big/broad picture, which doesn't work with programming, but it helps me with my understanding of it.


The questions you ask aren't unanswerable. They're just not answerable in a theoretical way. If you truly are interested in writing efficient code, then the only way to do it is to actually measure the performance with different code and work out which is more efficient. This video is really interesting in terms of how you really need to understand how things work down to the CPU cache level (and how you have to measure to see what is going on) if you want to write the most optimal code: https://www.youtube.com/watch?v=WDIkqP4JbkE

The problem with worrying about efficiency too soon (in the absolute sense) is that the changes you have to make to code to really make it efficient often make the code worst in terms of readability and maintainability. And if the efficiency you're gaining is so minor in that it makes absolutely no difference to a user of your software, then you end up with code that's harder to work with for questionable gain. if you're doing it for fun, then by all mean, go for it! Just keep in mind that the only way to really improve code efficiency is to measure before and after.

In the case for the question you're asking - function call vs object script attribute call - if I were to say to you that a function call might be slightly more efficient than a script attribute call, then it would be a disservice to you: it still wouldn't justify using one over the other, as they serve different needs and designs. And trying to use functions when script attributes would give a better design might end up with worse performance, as you'd have to possibly use more code to implement - with performance hit - what you really need by trying to avoid a "slower" feature. That's again why you can't just look at A vs B. You need to look at the overall code and the implementation you need and measure it in context given the larger code picture. In that sense, being higher level will actually serve you better - write good code at the high level and then dive down to the micro level to optimize where needed once the code works. And if you want to know how different kinds of code perform... measure! Then you'll know. :)

Your questions are all answerable. You just might have to work for it.


yea, design, is a huge factor, as well as "developer's time/effort" as my prof says, is a huge factor too, aka "it's not worth the effort/time you'd have to put in compared to the reward/achievement of whatever you might gain: efficiency/performance/limiting memory usage/great organized efficient scalable/editable design/etc" of yourself (completion speed/minimal effort, IS just as important as performance/results/etc). I was just indeed asking in the theoretical way, ignoring these other vital factors in actual practice (design, "developer's time/effort", etc).

P.S.

thanks for the link/vid !!! (watching it right now, lol)

P.S.S.

lots of videos... I'm going to be busy for quite a while, lol. I got a lot of videos to watch! :D

again thanks, wow great resource, all these tech conference/seminar videos! thank you for them!


Hello and merry xmas, happy holidays or any way you wish to express this beautiful winter joy <( ̄︶ ̄)>

Again, sorry for the super late reply, my real life presence is more important to my family than my questing time :p

I tried Jay's code and it almost worked! AAAGH it is too close but yet far from done! My problem is that it does work, but not when the indentation changes D:

I tried to use it on my main menu screen to show two sentences before the menu and it gave me a compilation error.

For example, this does not work:

section = StartNewOutputSection()
msg ("<br><br>")
PrintCentered ("<b>Inspired by We Lost The Sea's work<b>")
msg ("<br><br><br>")
EndOutputSection (section)
SetTimeout (3) {
  HideOutputSection (section)
  section = StartNewOutputSection()
  msg ("<br><br>")
  PrintCentered ("<b>Made with Quest<b>")
  msg ("<br><br><br>")
  EndOutputSection (section)
  SetTimeout (3) {
    HideOutputSection (section)
    PrintCentered ("Please type the option you wish to proceed with.<br/><br/><br/>- <b>New game</b> - <br/>- <b>Restore game</b> -<br/><br/><br/>")
  }
}

But this one does work, at least for instantly showing and hiding the first text and showing the second one three seconds later:

section = StartNewOutputSection()
msg ("<br><br>")
PrintCentered ("<b>Inspired by We Lost The Sea's work<b>")
msg ("<br><br><br>")
EndOutputSection (section)
HideOutputSection (section)
SetTimeout (3) {
  section = StartNewOutputSection()
  msg ("<br><br>")
  PrintCentered ("<b>Made with Quest<b>")
  msg ("<br><br><br>")
  EndOutputSection (section)
  SetTimeout (3) {
    HideOutputSection (section)
    PrintCentered ("Please type the option you wish to proceed with.<br/><br/><br/>- <b>New game</b> - <br/>- <b>Restore game</b> -<br/><br/><br/>")
  }
}

My deduction is that, when the indentation is changed and the HideOutputSection function is called inside a subscript (either wait and get input are described as 'wait/get input and run a script) Quest fails to recognize the section variable, since it was declared in another script. Also, HideOutputSection makes the text move when fading, and I need a non-fading, non-moving way to make it disappear xD

Any ideas?

Btw, thank both of you very much for your great help with this problem. I admire how you keep the forums alive with love for IF games. Is there a place, aside from the Quest documentation, where I can find more information about functions and code to use while developing?

Thank you very much ^^

PS: I just saved your video in my watch later tab. I'll check it when I'm on wifi :p


I don't think so, aside from the forums' (this one and the 'library and code samples' forum) posts/threads and scouring through the quest code/files.


You have identified the problem, which is that nested scripts don't generally have access to the variables used in the outer script scope (this is called a "closure", and, sadly, it doesn't work like that in Quest). I used "generally" because some do preserve the enclosing variables (e.g. "get input" and, I think, "wait". Since you used "get input" in your question, that was the one I tested).

The solution, though a bit ugly, is to store the section variable as the attribute of an object. For example, if you use "game.section" or "player.section" instead of just plain "section" in the code, then the value will be stored and accessed globally in all scripts. It does mean you need to attach it to some object (you can decide which - it might even make sense to store it as an attribute of the room the player is in), and you have to be careful about multiple scripts using the same variable for different purposes if you use the technique a lot. But that might not be that big of an issue in this case.


Jay, that's brilliant! I'll test it when I get on the pc and will tell you how it works. Thank you very much ^^

Also, I'll lurk the forums and games for more docs. Thank you too hegemonkhan :)


It works!!!!!!!

The only little thing that it needs to be perfect is a way to have the text disappear with no movement and no fade. Any ideas on how to do this?


Drop this function into your game:

  <function name="HideOutputSectionNow" parameters="name">
	JS.eval("$('." + name+"').hide(0, function () { $(this).remove(); });")
  </function>

and then use HideOutputSectionNow instead of HideOutputSection.


Mmmmm, sorry if I am the most illiterate coder here, but I cannot make it work. When I place the function, I get an error saying Error running script: Too many parameters passed to HideOutputSectionNow function - 1 passed, but only 0 expected, but if I delete the parameters I get Error running script: Error compiling expression '"$('." + name+"').hide(0, function () { $(this).remove(); });"': Unknown object or variable 'name'.

I'm like 100% sure I have to replace the name, function () and this with my own code, but I'm still too nooby to do it ;_;

If you can help me with this last piece I will immediately post here the full result so you can see it ^^


You shouldn't need to replace anything in the function. Just be sure to add the code in the main game body (e.g. insert it right before the closing "</aslx>" tag at the bottom, or after the closing "</game>" tag).

Are you using the Windows desktop version or the online editor?


I'm using the online editor. I know it's heresy, but it lets me work on the game while on my cell xD

Still, I test all this things on the Windows desktop first, then copy them to the web.

I'm going to recheck everything as you said.


Well, this is what I've accomplished, but as hard as I try I cannot make the HideOutputSectionNow work. I know this is a bit abrupt, but here is my code.

Also, I used the command bar function you posted in other thread. You are a hero!

<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Further Shores">
    <inherit name="theme_novella" />
    <gameid>bebc055b-d16a-4f31-bca0-e07f88346a6c</gameid>
    <version>Alpha 0.1</version>
    <firstpublished>2016</firstpublished>
    <author>Groctel</author>
    <category>Sci-Fi</category>
    <enablehyperlinks type="boolean">false</enablehyperlinks>
    <menufont>Georgia, serif</menufont>
    <feature_limitinventory />
    <feature_lightdark />
    <appendobjectdescription />
    <multiplecommands />
    <showpanes type="boolean">false</showpanes>
    <showcommandbar />
    <showlocation type="boolean">false</showlocation>
    <autodisplayverbs type="boolean">false</autodisplayverbs>
    <attr name="autodescription_youcansee" type="int">3</attr>
    <attr name="autodescription_youcango" type="int">0</attr>
    <attr name="autodescription_description" type="int">2</attr>
    <attr name="autodescription_youarein_useprefix" type="boolean">false</attr>
    <defaultfont>Georgia, serif</defaultfont>
    <defaultfontsize type="int">12</defaultfontsize>
    <autodescription_youarein_newline />
    <cover>Cover.png</cover>
    <pov type="object">AAA_Player</pov>
  </game>
  <object name="Main">
    <inherit name="editor_object" />
    <object name="Main_Menu">
      <inherit name="editor_room" />
      <objectslistprefix type="string"></objectslistprefix>
      <alias type="string"></alias>
      <usedefaultprefix type="boolean">false</usedefaultprefix>
      <description type="script"><![CDATA[
        HideCommandBar
        Main.section = StartNewOutputSection()
        msg ("<br><br>")
        TextFX_Unscramble ("Inspired by We Lost The Sea's work", 100, 1)
        EndOutputSection (Main.section)
        JS.eval ("$('."+Main.section+"').css('text-align', 'center').css('font-weight', 'bold');")
        SetTimeout (5) {
          HideOutputSection (Main.section)
          SetTimeout (1) {
            Main.section = StartNewOutputSection()
            msg ("<br><br>")
            TextFX_Unscramble ("Made with Quest", 100, 1)
            EndOutputSection (Main.section)
            JS.eval ("$('."+Main.section+"').css('text-align', 'center').css('font-weight', 'bold');")
            SetTimeout (3) {
              HideOutputSection (Main.section)
              SetTimeout (1) {
                Main.section0 = StartNewOutputSection()
                TextFX_Unscramble ("Please type the option you wish to proceed with.", 100, 1)
                EndOutputSection (Main.section0)
                JS.eval ("$('."+Main.section0+"').css('text-align', 'center');")
                msg ("<br><br>")
                Main.section1 = StartNewOutputSection()
                TextFX_Unscramble ("- New game -", 100, 1)
                EndOutputSection (Main.section1)
                JS.eval ("$('."+Main.section1+"').css('text-align', 'center').css('font-weight', 'bold');")
                Main.section2 = StartNewOutputSection()
                TextFX_Unscramble ("- Restore game -", 100, 1)
                EndOutputSection (Main.section2)
                JS.eval ("$('."+Main.section2+"').css('text-align', 'center').css('font-weight', 'bold');")
                msg ("<br><br>")
                SetFontSize (8)
                TextFX_Typewriter ("©Groctel // Alpha 0.1", 100)
                SetFontSize (12)
                SetTimeout (5) {
                  ShowCommandBar
                }
              }
            }
          }
        }
      ]]></description>
      <object name="AAA_Player">
        <inherit name="editor_object" />
        <inherit name="editor_player" />
        <look>Looking good.</look>
        <gender>you</gender>
        <article>you</article>
      </object>
    </object>
  </object>
  <function name="HideCommandBar">
    request (Hide, "Command")
  </function>
  <function name="ShowCommandBar">
    request (Show, "Command")
  </function>
  <function name="HideOutputSectionNow">
    JS.eval ("$('." + name+"').hide(0, function () { $(this).remove(); });")
  </function>
</asl>

I'm obviously crediting you for all you've done to help me!

Thank you very much <3


The HideOutputSectionNow function has lost its parameter. It should have a parameters="name" attribute. Check out the original code. If you can't edit it in the script view, you should be able to add the parameter via the GUI editor for the function.


Done! Here is a link to the menu intro file ^^

http://play.textadventures.co.uk/Play.aspx?id=msbosynqs0oow7sxeld9ba

Thank you very very much for your help <3


Glad it's all working now. :)


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

Support

Forums