Author Topic: Scripts  (Read 5066 times)

  • Administrator
  • Sr. Member
  • *****
  • Posts: 407
    • View Profile
Re: Scripts
« Reply #30 on: October 04, 2021, 01:39:05 pm »
tabby, whats the best method for saving, loading, and modifying save data?
Because Flash has no file write feature (it barely has any means of file read access) the only way to save data is AS2 SharedObject class. It was originally designed for web browser flash player for online flash programs to save some little data locally in user computer the same way web page cookies are stored. Standalone Flash Projector saves the same data deep in <user>\Application_data\... folder. That way you can save and load player settings (not all) and NPC dialog progress in HTH_vT067x.

If you want to do any Flash programming seriously, check following ActionScript 2 language reference manual. It describes literally everything you could need to know about AS2.
https://anonfiles.com/N0U544Lcu2/as2-langref_pdf
However, it's in the form of reference manual. So it expects user to be somewhat experienced in programming and be familiar with programming terms to fully understand that. If you know how to program and just need to find how to do that in this particular language, a reference manual is exactly what you need.

  • Administrator
  • Sr. Member
  • *****
  • Posts: 407
    • View Profile
Re: Scripts
« Reply #31 on: October 04, 2021, 01:47:41 pm »
Oh and does anybody got any recommendations for what program I can use to edit flash files? Since Adobe liked off flash what kind of alternatives can I use?
I use FFDec. It's really low level SWF file editor, not much user friendly. Also it has bugs because it is someone's free time project. But it can works with any obfuscation methods used by third party tools to prevent de-compilation. Crow has used these on most HTH files.
It is available also for Linux, unlike many other Flash tools which are MS Windows only. 1r2 knows more about Flash tools. That matters for me because I have no Windows OS in my computer and Wine typically doesn't work with software requiring installation or integration with OS.

  • Newbie
  • *
  • Posts: 21
  • Location: United States
    • View Profile
Re: Scripts
« Reply #32 on: October 04, 2021, 01:52:42 pm »
Sounds like a pain. Figured i got a Windows myself I wanted to fiddle around with the animations and coding in the game.
===================================================================
See ya, Bladerunner.

===================================================================

  • Hero Member
  • *****
  • Posts: 509
    • View Profile
Re: Scripts
« Reply #33 on: October 04, 2021, 01:55:52 pm »
Flash works on playonlinux im pretty sure

  • Hero Member
  • *****
  • Posts: 509
    • View Profile
Re: Scripts
« Reply #34 on: October 04, 2021, 08:56:36 pm »
okay, nice to know I'm not completely stupid. the issue is that I've set a few _root variables similar to the _root.filename implementation, but when I update their values, it doesn't seem to make any changes. What gives?

  • Administrator
  • Sr. Member
  • *****
  • Posts: 407
    • View Profile
Re: Scripts
« Reply #35 on: October 05, 2021, 08:43:27 pm »
1r2> I haven’t seen your code so I can’t tell what’s wrong.

Generally, you use SharedObject class by declaring variable of it's type, which is by default calling object’s constructor. That is a function which you pass a parameter of stored data set name.

Let’s do it at _root level. You can place it in main timeline key frame which is at _root level so you don’t need to prefix “_root.” pointer before every identifier.

var savedata:SharedObject = SharedObject.getLocal("HTHbetaSave");

This creates object _root.savedata with some functions defined by ShareObject class and named list _root.savedata.data containing all variables that Flash Player could find in HTHbetaSave storage file. These data were loaded at the time the constructor was called, i.e. the game start.

Now you need some load function for load button to assign your game variables with values found in that loaded “savedata” object. Let’s say you have _root.species and _root.dicksize :-) variables defined with some current or default values. Let’s create load function.
saveload = function()
{
  if (_root.savedata.data.species != undefined)
   {
      _root.species = _root.savedata.data.species;
   }
  if (_root.savedata.data.dicksize != undefined)
   {
      _root.dicksize = _root.savedata.data.dicksize;
   }
}

Note1: You can omit _root. if function is defined at root level, because in Flash function has scope of place where it's defined, not from where it's called.
Note2: You have to always check that variable is defined in save data before overwritting your variable.
Now create a button (see another page of this thread on how to) and define it's action:
loadbutton.onRelease = function()
   {
     _root.saveload();
   }

... or you can paste previous function body into button function directly.

Then you need some save function for save button to get your game variables to savedata object. It's opposite of above, just you don't need to check anything, list items are created simply by assignment.
savesave = function()
{
    _root.savedata.data.species = _root.species;
    _root.savedata.data.dicksize = _root.dicksize ;
}

You don't need to call anything to actually write the data to the disk, the Flash Player does that automatically on program exit. (Now I actually don't know if AS2 has object destructor functions as it doesn't have a delete operator to explicitly undo data structures and to free memory. If it does, that would be logical place for file save.)
If you want to force Flash Player write data to the disk on button press anyway, you can add statement
_root.savedata.flush();
on the end of that savesave function. But there is no reason to unless your player usually terminates by crashing.
Now create save button calling (or containing) that function and it's done.

I don't guarantee that this works, I didn't test that. It's just a quick idea.

  • Administrator
  • Sr. Member
  • *****
  • Posts: 407
    • View Profile
Re: Scripts
« Reply #36 on: October 06, 2021, 10:18:47 pm »
I'm technically wrong in my previous post. Shared object data are loaded from disk storage not by SharedObject class constructor upon object declaration, but by calling it's getLocal(...) function which is practically used as an additional object constructor.
SharedObject is otherwise static class so it's formal constructor is most likely empty.
I'm sorry for confusion. I shouldn't post such things tired late in the night.

Maybe I should note short dictionary:
Object = data structure, like variable, but more complex, holding multiple variables and also functions for operations with that data.
Objects are dynamically created and removed in the dynamic data part of program memory (heap) during program run.
Class = sort of static template for object of particular type. Also contains function for creating object (constructor) and removing object (destructor), both called automatically. It is located in the fixed part of program memory and it cannot hold any data.
There are some language dependent exceptions.
Anyway, I'm doing the same mistake again by pulling this form my ... late in the night, so it may be inaccurate. After all I'm even not a programmer.

  • Hero Member
  • *****
  • Posts: 509
    • View Profile
Re: Scripts
« Reply #37 on: October 07, 2021, 03:45:59 am »
I'm already pretty accustomed to actionscript 2
I just couldn't get the data to override. I'll get it working as soon as possible.

  • Hero Member
  • *****
  • Posts: 509
    • View Profile
Re: Scripts
« Reply #38 on: October 07, 2021, 04:18:28 pm »
The data stored in so.data appears to be a table. Can I reference the values by index?

  • Newbie
  • *
  • Posts: 21
  • Location: United States
    • View Profile
Re: Scripts
« Reply #39 on: October 10, 2021, 02:42:53 am »
Sorry I haven't been active as much. Had like my first set of exams last week.

The data stored in so.data appears to be a table. Can I reference the values by index?

I mean, you should. Its the root data is it not? I've been learning coding recently so I'm not entirely too sure
===================================================================
See ya, Bladerunner.

===================================================================

  • Hero Member
  • *****
  • Posts: 509
    • View Profile
Re: Scripts
« Reply #40 on: October 10, 2021, 04:22:08 am »
I figured, but the values don't update when I run tests. I need to make sute I'm clearimg data correctly. Will have to implement soon

  • Newbie
  • *
  • Posts: 21
  • Location: United States
    • View Profile
Re: Scripts
« Reply #41 on: October 10, 2021, 05:38:10 pm »
I figured, but the values don't update when I run tests. I need to make sute I'm clearimg data correctly. Will have to implement soon

I wonder if it is something hard-coded related in the data file. Idk I could be wrong, but would have to code in a new save method either to an external file to manually load but that would be us having to comb through the menu and UI stuff.
===================================================================
See ya, Bladerunner.

===================================================================

  • Administrator
  • Sr. Member
  • *****
  • Posts: 407
    • View Profile
Re: Scripts
« Reply #42 on: October 10, 2021, 06:26:32 pm »
1r2> Please send me the files and tell me what is supposed to do. I believe I can figure it out.
I really busy IRL but I hope I can squeeze it in a week.

  • Hero Member
  • *****
  • Posts: 509
    • View Profile
Re: Scripts
« Reply #43 on: October 10, 2021, 08:35:10 pm »
Ok cool. You can also test the build I have in place. I already am aware of most of the bugs, I just need the save/ load function to work.

  • Administrator
  • Sr. Member
  • *****
  • Posts: 407
    • View Profile
Re: Scripts
« Reply #44 on: October 12, 2021, 07:11:24 am »
1r2> I can't find any attempt to save or load anything in the scripts. Also I can't find any save or load button. Where it is supposed to be?

My other notes:
1. Character chat exit should return player on the place where he entered the chat = level file should jump to the frame where the character is.
Didn't I implemented something like start point in previous version?
Means that for example MainHall floor 2:
Rio button should have also statement:
_root.startpoint = "mh2_rio";
Tanya button should contain
_root.startpoint = "mh2_tanya";

The first frame of the level should have frame script:
if (_root.startpoint == "mh2_rio")
{
  gotoAndStop("2c");
}
else
{
  gotoAndStop("2a");
}
Tanya is right in the "2a"  frame so no need for condition for her.
Map button for any level using start points should clear the variable by _root.startpoint = "none"; just for sure that old value doesn't interfere.

2. Main Hall levels could have "Back to elevator" button jumping player in front of elevator for easier navigation.

3. Previous HTH beta Jezzel sprite looked better than current version. I hoped she could be saved.
« Last Edit: October 12, 2021, 07:15:35 am by Tabby »