Help with a status attribute [solved]

Okay, I know this is probably in the tutorial, but not in a way that made 100% perfect enough sense to me that I absorbed it in a way that allowed me to adapt it to my new game.

I have a status attribute named "credits". It's the game's money. The character needs access to this, and at points it'll be increased or decreased when [thing] occurs, I can figure out how to access it, that's simple. But I can't think of how to update it.

Example of what I need to happen but can't figure out how to code properly:

At a point the character checks their credits balance via an object (a datapad with an object [bank app] attached that look at will run a script that prints [credit balance].) The first time this happens I'll add an attribute [gifted] to [bank app] that increases [credit balance] by [integer]. The second time, it'll check for the [gifted] attribute then if it finds it will just print [credit balance]. At at least one other point the character will buy something and that also updates the credit balance, but I can't figure out how to set up the function for credits so I don't have to keep adding the if statements and changing it all manually for each encounter that changes the amount and can instead just call the function to update [credits].

I know I need to add a script that's like print expression "You have " + player.credits + "credits." but that would just be for checking the amount in the player.credits attribute, not updating it. How would I update it? This is important because eventually the game will be updated with more quests/chapters and the player will buy or sell objects more times and get more [gifted] attributes, if I can figure out this stuff to make the first test chapter in the first place.

Am I going about it wrong? Should the credits be an object all their own that the player begins with having in their inventory and can be updated over time (can an object be updated often like that)? Would that make more sense anyways or is it better to have it as a status attribute? Any help would be appreciated, since it's probably highly likely just something I'm overlooking/overthinking.


Here is the code for an example i made that might help, make a new game go to code view and paste this in there over the other code.

<!--Saved by Quest 5.6.6108.15891-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Money">
    <gameid>4caeab59-8381-4c77-adbc-f3625fc6b748</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <credits type="int">0</credits>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
      <Credits type="int">0</Credits>
      <statusattributes type="stringdictionary">
        <item>
          <key>Credits</key>
          <value></value>
        </item>
      </statusattributes>
    </object>
    <object name="orange">
      <inherit name="editor_object" />
      <inherit name="Bank" />
      <cost type="int">-5</cost>
      <displayverbs type="stringlist" />
      <inventoryverbs type="stringlist">
        <value>Use</value>
        <value>Drop</value>
      </inventoryverbs>
      <useindividualverblist />
      <buy type="script"><![CDATA[
        if (not Got(this)) {
          if (GetInt(player, "Credits") >= 5) {
            do (this, "payment")
            AddToInventory (this)
          }
        }
      ]]></buy>
      <payment type="script">
        player.Credits = player.Credits + this.cost
        msg ("You have " +player.Credits+ " credits.")
      </payment>
    </object>
    <object name="NPC">
      <inherit name="editor_object" />
      <inherit name="Bank" />
      <cost type="int">5</cost>
      <displayverbs type="stringlist">
        <value>Look at</value>
      </displayverbs>
      <inventoryverbs type="stringlist">
        <value>Look at</value>
      </inventoryverbs>
      <sell type="script">
        if (Got(orange)) {
          MoveObject (orange, NPC)
          do (this, "payment")
        }
        else {
          msg ("You have nothing i want.")
        }
      </sell>
    </object>
    <object name="Data_Pad">
      <inherit name="editor_object" />
      <inherit name="openable" />
      <feature_container />
      <openscript type="script">
      </openscript>
      <closescript type="script">
      </closescript>
      <take />
      <listchildren type="boolean">false</listchildren>
      <isopen type="boolean">false</isopen>
      <displayverbs type="stringlist">
        <value>Look at</value>
        <value>Take</value>
      </displayverbs>
      <inventoryverbs type="stringlist">
        <value>Look at</value>
        <value>Use</value>
        <value>Drop</value>
      </inventoryverbs>
      <feature_usegive />
      <use type="script">
        if (Data_Pad.isopen) {
          HelperCloseObject (Data_Pad)
        }
        else {
          HelperOpenObject (Data_Pad)
        }
      </use>
      <object name="Bank_App">
        <inherit name="editor_object" />
        <inherit name="Bank" />
        <cost type="int">1000</cost>
        <checkbank type="script">
          if (this.gifted = False) {
            this.gifted = True
            do (this, "payment")
          }
          else {
            msg ("You have " +player.Credits+ " credits in bank.")
          }
        </checkbank>
      </object>
    </object>
  </object>
  <verb>
    <property>deposit</property>
    <pattern>deposit</pattern>
    <defaultexpression>"You can't deposit " + object.article + "."</defaultexpression>
  </verb>
  <verb>
    <property>withdraw</property>
    <pattern>withdraw</pattern>
    <defaultexpression>"You can't withdraw " + object.article + "."</defaultexpression>
  </verb>
  <verb>
    <property>sell</property>
    <pattern>sell</pattern>
    <defaultexpression>"You can't sell " + object.article + "."</defaultexpression>
  </verb>
  <verb>
    <property>checkbank</property>
    <pattern>check bank</pattern>
    <defaultexpression>"You can't check bank " + object.article + "."</defaultexpression>
  </verb>
  <type name="Bank">
    <cost type="int">0</cost>
    <payment type="script">
      player.Credits = player.Credits + this.cost
      msg ("You have " +player.Credits+ " credits.")
    </payment>
    <gifted type="boolean">false</gifted>
  </type>
</asl>

If you need help understanding it let me know.


Okay, let me try it like this

player object has status attribute credits that is an integer. player.credits=100 (not sure if that formatting is right just an example.)

When the player interacts with the object "bank app" in the container "data pad" it does something like this

if (bank_app.gifted = false) {
    msg "You have " + player.credits+1000 + "credits."
    bank_app.gifted = true
} else {
    msg "You have " + player.credits + "credits."
}

When the player buys something from a shop keeper I need to be able to affect player.credits by a different amount each time depending on what's bought. What I'm looking for is help setting a function I can call on to change the credits amount without having to type the code in each time.

Like, I need help figuring out how to set it up so that player.credits is changed by a different value that is determined as part of an if statement when the function is called. Would it be easier to set it up with all buyable objects having an object.credits attribute value that the function can call upon to determine how much is added or subtracted from player.credits or is there some other way to do it that I'm just not aware of?

For example would this be correct:

if (object.isbuying = true) {
    player.credits-object.credits=player.credits 
    msg "You purchased " + object.alias + " and spent " + object.credits + " check the bank app on your data pad for your new credits balance at your earliest convenience."
} else {
    msg "You decided not to buy " + object.alias +"."
}

and when the player eventually completes a quest: [X=the quest number which will change and XXXX is the number of credits to be added by the quest]

if (bank_app.giftedX = false) {
    msg "You have " + player.credits+XXXX + "credits."
    bank_app.giftedX = true
} else {
    msg "You have " + player.credits + "credits."
}

I mostly just want to make sure I'm not overcomplicating something that can be done in a much simpler manner, for buying things, and help with understanding if my second idea about how to handle quest rewards is even viable or if I'm doing it incorrectly. I'm sorry if my wording was confusing at first (or still is), it's been a long day and I'm not the best at explaining things when I ask questions (I do apologize for that).


Okay, I see what you did in your code and I like it and it makes sense to me. Now I'm curious if what I did example would also work, and which way is actually better. (I'm also really curious about the second part of my example/question, because I would like the player to be able to do things for NPCs and be paid for it, but if that's too complicated to handle or if there's a simpler way, I'd love to hear about it.)


Do you have discord or another chating service we could talk? Actually here is my teamspeak server ts03-usla.nitrado.net:11450

Also changed the code added in a data pad with a bank app in it. Take data pad then use it and bank app will appear, then click check bank verb and there you go, 1000 credits will be added so you can buy orange then sell it to NPC.


EDIT: I didn't see your edit before I managed to post mine, let me check your new edit and then edit this with any new question it might have raised.

EDIT2: Okay, after looking at your code both as code and in the GUI, your code does exactly what I am hoping my code does. Which tells me that the way I was going to set it up in the GUI does work and is the right way. Thank you, so much for your help.

-- original post--
No, I'm afraid that I don't. Those kind of things really mess with my anxiety (I'm sorry, I know that's not really helpful for more immediate help). If it helps any with answering the question about updating the bank amount after quests: would it be as simple as adding an if to the end of the final part of the quest that says basically:

if (quest.complete = true) {
    player.credits+quest.reward
    msg "Quest Complete, you have been paid and may now move on."
} else {
    msg "You did not get paid because you did not complete the quest."
}

And I realize after comparing our codes again, that I do not need the =player.credits after player.credits+object.credits in my code.

Again, I apologize if it doesn't make sense/what I'm trying to do isn't obvious. I should have made it clearer from the beginning that I'm most comfortable working with the gui, but I am learning the code too, and I'm really new at this. But, I looked at what your code does in the GUI and I think my code is essentially doing the same thing just with different attributes/more generally.

Basically what's happening in both cases (and what I need to happen) is I have my credits being affected by the appropriate attribute of the object that the player is interacting with. The main difference being in mine, there's code before that I left out, that shows that the shop keeper is a container that player interacted with and when you pick an object the shop keeper asks you if you want to buy the object, if you reply yes it sets a boolean flag on the object that allows the script for buying the object to run; but in yours player buys the object without having to go through the npc/shop keeper container to do that.

If this is all true, i.e. if it's all correct, then everything is good and I'm just overthinking/overanalysizing things and the problem is actually solved.


This line:

player.credits+quest.reward

Should be:

player.credits = player.credits+quest.reward

After you add the two things together, you need to assign the result to something. I.e., the credits has to become the old value for the credits plus the reward.


When you do the math for adding quest reward you want it to like this

if (quest.complete = true) {
    player.credits = player.credits + quest.reward
    msg "Quest Complete, you have been paid and may now move on."
} else {
    msg "You did not get paid because you did not complete the quest."
}

There is no way for the code to work just saying player.Credits + quest.reward because then it has no attribute to actually add/set to.
And all I use is GUI editor and have made tutorials on using the editor to do alot that I have learn't through out time. Here is Channel I have been slacking mostly to do with lack of interest from others as it takes time to make videos, edit etc. so if no one really watches whats the point right lol. But im always up to do a special video for someone if I know exactly what they're trying to do.


This should be my final post unless I messed up, having made the edits to your code, onimike, to test my quest before implementing it in a real game. This is the code I now have {I realize that the code to complete the quest is labeled changedcomplete, I had originally made a mistake in how the flag worked, but when I test the code it does everything I want it to, so I think that's okay}:

<!--Saved by Quest 5.6.6108.15891-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Money">
    <gameid>4caeab59-8381-4c77-adbc-f3625fc6b748</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <credits type="int">0</credits>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
      <Credits type="int">0</Credits>
      <statusattributes type="stringdictionary">
        <item>
          <key>Credits</key>
          <value></value>
        </item>
      </statusattributes>
    </object>
    <object name="orange">
      <inherit name="editor_object" />
      <inherit name="Bank" />
      <cost type="int">-5</cost>
      <displayverbs type="stringlist" />
      <inventoryverbs type="stringlist">
        <value>Use</value>
        <value>Drop</value>
      </inventoryverbs>
      <useindividualverblist />
      <buy type="script"><![CDATA[
        if (not Got(this)) {
          if (GetInt(player, "Credits") >= 5) {
            do (this, "payment")
            AddToInventory (this)
          }
        }
      ]]></buy>
      <payment type="script">
        player.Credits = player.Credits + this.cost
        msg ("You have " +player.Credits+ " credits.")
      </payment>
    </object>
    <object name="NPC">
      <inherit name="editor_object" />
      <inherit name="Bank" />
      <cost type="int">5</cost>
      <displayverbs type="stringlist">
        <value>Look at</value>
      </displayverbs>
      <inventoryverbs type="stringlist">
        <value>Look at</value>
      </inventoryverbs>
      <sell type="script">
        if (GetBoolean(quest, "taken")) {
          if (Got(orange)) {
            MoveObject (orange, NPC)
            do (this, "payment")
          }
          else {
            msg ("You have nothing i want.")
          }
        }
        else {
          msg ("You cannot do that unless you have taken the quest.")
        }
      </sell>
      <payment type="script">
        player.Credits = player.Credits + this.cost
        msg ("You have " +player.Credits+ " credits.")
        SetObjectFlagOn (quest, "complete")
      </payment>
    </object>
    <object name="Data_Pad">
      <inherit name="editor_object" />
      <inherit name="openable" />
      <feature_container />
      <take />
      <listchildren type="boolean">false</listchildren>
      <isopen type="boolean">false</isopen>
      <displayverbs type="stringlist">
        <value>Look at</value>
        <value>Take</value>
      </displayverbs>
      <inventoryverbs type="stringlist">
        <value>Look at</value>
        <value>Use</value>
        <value>Drop</value>
      </inventoryverbs>
      <feature_usegive />
      <openscript type="script">
      </openscript>
      <closescript type="script">
      </closescript>
      <use type="script">
        if (Data_Pad.isopen) {
          HelperCloseObject (Data_Pad)
        }
        else {
          HelperOpenObject (Data_Pad)
        }
      </use>
      <object name="Bank_App">
        <inherit name="editor_object" />
        <inherit name="Bank" />
        <cost type="int">1000</cost>
        <checkbank type="script">
          if (this.gifted = False) {
            this.gifted = True
            do (this, "payment")
          }
          else {
            msg ("You have " +player.Credits+ " credits in bank.")
          }
        </checkbank>
      </object>
    </object>
    <object name="quest">
      <inherit name="editor_object" />
      <usedefaultprefix type="boolean">false</usedefaultprefix>
      <prefix>one</prefix>
      <look>The quest is that you must sell the orange to the npc.</look>
      <take />
      <reward type="int">100</reward>
      <ontake type="script">
        SetObjectFlagOn (quest, "taken")
      </ontake>
      <changedcomplete type="script">
        if (GetBoolean(quest, "complete")) {
          UnlockExit (Goal)
          player.Credits = this.reward + player.Credits
          msg ("Quest Complete")
          msg ("You now have " +player.Credits+ " credits.")
          msg ("You've been rewarded you may proceed to the exit.")
        }
        else {
          msg ("You have not completed the quest")
        }
      </changedcomplete>
    </object>
    <exit name="Goal" alias="south" to="end">
      <inherit name="southdirection" />
      <locked />
    </exit>
  </object>
  <verb>
    <property>deposit</property>
    <pattern>deposit</pattern>
    <defaultexpression>"You can't deposit " + object.article + "."</defaultexpression>
  </verb>
  <verb>
    <property>withdraw</property>
    <pattern>withdraw</pattern>
    <defaultexpression>"You can't withdraw " + object.article + "."</defaultexpression>
  </verb>
  <verb>
    <property>sell</property>
    <pattern>sell</pattern>
    <defaultexpression>"You can't sell " + object.article + "."</defaultexpression>
  </verb>
  <verb>
    <property>checkbank</property>
    <pattern>check bank</pattern>
    <defaultexpression>"You can't check bank " + object.article + "."</defaultexpression>
  </verb>
  <object name="end">
    <inherit name="editor_room" />
    <usedefaultprefix type="boolean">false</usedefaultprefix>
    <prefix>the</prefix>
    <descprefix>You are at</descprefix>
    <enter type="script">
      finish
    </enter>
  </object>
  <type name="Bank">
    <cost type="int">0</cost>
    <gifted type="boolean">false</gifted>
    <payment type="script">
      player.Credits = player.Credits + this.cost
      msg ("You have " +player.Credits+ " credits.")
    </payment>
  </type>
</asl>

too late, but I got guides on this stuff


quest's scripting: 'Attributes' and the 'if' Script usage:

https://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk
http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk

and here's a step by step demo game guide on the basics of Attributes (including statusattribute usage):

https://textadventures.co.uk/forum/quest/topic/5387/i-really-need-help#37375
or
http://textadventures.co.uk/forum/quest/topic/5387/i-really-need-help#37375

and if interested on Lists/Dictionaries:

https://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk
https://textadventures.co.uk/forum/samples/topic/5138/explore-and-travel-code-sample-by-hk (this is old and bad code, with some errors/ineffeciencies, as this was when I was first learning this stuff, lol)
or
http://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk
http://textadventures.co.uk/forum/samples/topic/5138/explore-and-travel-code-sample-by-hk (this is old and bad code, with some errors/ineffeciencies, as this was when I was first learning this stuff, lol)


It's not too late, I had actually hoped at least one other person would give advice at the very least about the last post. Your guide about Attributes and the "if" Script is what influenced my second post into having proper code in it code that I'm pretty sure actually works :). The guides you keep providing me are very useful to me. (I've been awake too long at this point and my words are starting to become harder to make actually make sense without sounding oversimplified or confused, oops.)


I know the experience... I've been up too long posting online myself... it's hard when you're so tired and barely awake. Keep up the work though, you'll be able to learn quest with some patience, as learning to code, just takes time, lots of practice (trouble-shooting), lol.


ask if you got any questions on anything, and/or if you need anything explained better (I'm not the best at explaining stuff, whereas Pixie, Jay, Pertex, and the others, are much better, and very concise, as they're all really good programmers and know quest very well)


Nice Subtletylost You made your fist quest with it. Well glad to have help I know Im not a coder like these other guys/gals on here so its nice to help when i can :)


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

Support

Forums