Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Pages: [1] 2  All

Author Topic: saving properties  (Read 9685 times)

0 Members and 1 Guest are viewing this topic.

Drax

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 78
  • This engine rocks!
    • View Profile
    • Ganja Joe - And the myth of the holy pot
saving properties
« on: April 06, 2004, 09:39:26 AM »

I hope that this is my last question for my property menu.

I want to have a external file, where I can store my variables
witch are set in my property menu. the file should be read at startup.
At first Installation the File is installed with standart settings and if I change something in my properties it schould be written in this file.
I have to store some char and integer varables.

Is there a include class like iostream?
Is it possible, that it works while developing in WME too (whithout pakages but not nessesary in debug mode)?

 ::) I know im asking much. :-\
but in a few weeks the demo will be finished and then I will be more quiet.  :-X

ThX Drax

Logged
I'm Lost!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:saving properties
« Reply #1 on: April 06, 2004, 10:16:06 AM »

Is it necessary that it's a file? WME allows you to write to and read from the windows registry. You can store numbers and strings there and read them later.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

MMR

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 349
  • http://mmrdeveloper.wordpress.com/
    • View Profile
    • TinyWME
Re:saving properties
« Reply #2 on: April 06, 2004, 11:43:33 AM »

McCoy and I did some kind of Plug-in for write and read from an external file. The problem is it doesn't work all the best it should (some incompatibilities with the current WME plug-in support I think)

Here is some piece of code (in C++ Standard):

Code: [Select]
#include <windows.h>
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

extern "C" __declspec(dllexport) void write_file(char* fileName, char* text)
{  
    string texto(text);
   
   // Writing the File
   ofstream file(fileName);
   
   file << texto << endl;
   file.close();
}

extern "C" __declspec(dllexport) void read_file(char* fileName, char* k)
{  
    string m, aux;
     
   ifstream read(fileName);
   
   if(!read.fail())
   {
      while(read)
      {
        getline(read, aux, '\n');
        m = m + aux + "\n";
      }
   }
   
   else cerr << "Error opening the file: Maybe the file doesn't exist or has a different name";
   
   read.close();
   
   k = new char[m.length()];
   strcpy(k, m.c_str());
   
   //delete(k);
   
}
« Last Edit: April 06, 2004, 11:50:31 AM by MMR »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:saving properties
« Reply #3 on: April 06, 2004, 12:03:54 PM »

What incompatibilities? :o
Anyway, I think the registry support will suffice for Drax's purposes.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Drax

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 78
  • This engine rocks!
    • View Profile
    • Ganja Joe - And the myth of the holy pot
Re:saving properties
« Reply #4 on: April 06, 2004, 12:42:39 PM »

yeah. that looks great.
 
It has not to be a file at all. If I can load and save the variables its absolutly sufficient.

I will try accommodate your script when im at home again.

But i think I have to ask once more in this threat. ;D
Logged
I'm Lost!

Drax

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 78
  • This engine rocks!
    • View Profile
    • Ganja Joe - And the myth of the holy pot
Re:saving properties
« Reply #5 on: April 06, 2004, 12:49:51 PM »

I've read a little bit in the wme help and the dll support should be the better and easyer solution.
Logged
I'm Lost!

McCoy

  • The cocido eater
  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 365
  • Spurrrrrrring
    • View Profile
    • Spur Games
Re:saving properties
« Reply #6 on: April 06, 2004, 12:53:21 PM »

The big issue about that C++ DLL was the memory leak because of the impossibility of unloading the file from memory at the end of the function... Otherwise, it worked as intended.

Jan told me another way to do it by loading, reading, and unloading the file using functions intended to be used in WME scripts instead of doing all the process in C++, but... I'm too lazy and unexperienced...  :-[
Logged

Click here to sign my sig!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:saving properties
« Reply #7 on: April 06, 2004, 01:02:00 PM »

Forget about plugins, just use the Game.RegWriteNumber(), Game.RegWriteString(), Game.RegReadNumber() and Game.RegReadString() methods :)
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Drax

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 78
  • This engine rocks!
    • View Profile
    • Ganja Joe - And the myth of the holy pot
Re:saving properties
« Reply #8 on: April 06, 2004, 01:16:27 PM »

That's the comfort I used to.  ;D ;D

You mean I only have to say Game.RegWriteNumber(bla) and It will be in the registry. Without doing something else.

But I need to have more than one Number. It always has to have a (var) name and a value.  ???

Maybe I misunderstanding that now.

 :-\        
Logged
I'm Lost!

McCoy

  • The cocido eater
  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 365
  • Spurrrrrrring
    • View Profile
    • Spur Games
Re:saving properties
« Reply #9 on: April 06, 2004, 01:35:21 PM »

Yep, I'm using the registry writing and reading functions for saving and recovering the subtitles speed value between game sessions, because it's not saved in the registry like the sound volume values.

The registry methods are used this way:

Code: [Select]
Game.RegWriteNumber("string", value);for example:
Code: [Select]
Game.RegWriteNumber("SubtitlesSpeed", 80);
For recovering the value, just write:

Code: [Select]
somevariable = Game.RegReadNumber("SubtitlesSpeed");
it's the same for the rest of methods.
« Last Edit: April 06, 2004, 01:35:59 PM by McCoy »
Logged

Click here to sign my sig!

odnorf

  • w00t?
  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 7
  • Offline Offline
  • Gender: Male
  • Posts: 1456
  • Lamp dog!
    • View Profile
Re:saving properties
« Reply #10 on: April 06, 2004, 04:22:35 PM »

« Last Edit: April 06, 2004, 04:23:20 PM by odnorf »
Logged
fl*p

Drax

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 78
  • This engine rocks!
    • View Profile
    • Ganja Joe - And the myth of the holy pot
Re:saving properties
« Reply #11 on: April 06, 2004, 04:39:43 PM »

I can't say it often enough, I love this engine!

I've thought, that I have to code (in my favorite methode: try and fail  ;)) for the next week to solve this load and save thing, but In Wintermude it's a thing of a few minutes.

ThX for help to all.

DraX
Logged
I'm Lost!

Drax

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 78
  • This engine rocks!
    • View Profile
    • Ganja Joe - And the myth of the holy pot
Re:saving properties
« Reply #12 on: April 06, 2004, 04:54:30 PM »

what happens if I try to load and I not set it before.

It would happen at first time of loading my property window. Would it be null or would it throw an exeption? (Log file)
Logged
I'm Lost!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:saving properties
« Reply #13 on: April 06, 2004, 04:59:58 PM »

what happens if I try to load and I not set it before.

It would happen at first time of loading my property window. Would it be null or would it throw an exeption? (Log file)

You can pass a second parameter with an init value, such as:

var Name = Game.RegReadString("Name", "Joe");

This will return "Joe" if the registry key doesn't exist yet.
If you don't specify any init value, the functions return null.
« Last Edit: April 06, 2004, 05:00:36 PM by Mnemonic »
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Drax

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 78
  • This engine rocks!
    • View Profile
    • Ganja Joe - And the myth of the holy pot
Re:saving properties
« Reply #14 on: April 06, 2004, 06:43:45 PM »

I'm pretty happy. ;D

Now it loads from reg. I controlled with regedit and all the values are changing correct.

ThX a lot

DraX
« Last Edit: April 06, 2004, 06:44:10 PM by DraX »
Logged
I'm Lost!
Pages: [1] 2  All
 

Page created in 0.036 seconds with 23 queries.