About making a dll library for use by game

Started by dullman, July 26, 2014, 02:59:11 pm

Previous topic - Next topic

ForeverZer0

Yes, you can reference a hash that way, but you will need to use double-quotes, since-single quotes in C# are for chars.

You do not need to write a converter, just make sure that any string that will be loaded by RMXP is not a System.String. You can simply use the extension method I gave you.

actor.name = "This is a C# string".ToRubyString();


// To use as a system string in C#
var name = actor.name.ToString();




I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

dullman

I asked in previous post after editing, but it seems it was after you answered so i ask one more time in new post.
Is there any clone method that return you a new copy of object for dynamic type?? Or i need to create it myself??

ForeverZer0

Have you tried this?

var copy = Ruby.Eval("some_object.clone")


If not, I have made a deep-clone method, but it I have never tested it on IronRuby types. It would normally require the object be serializable, but I am not sure if Ruby automatically makes objects serializable or not.

If not, you can just make modification of it to use Marshal instead of a BinaryWriter and BinaryReader.
Spoiler: ShowHide
		using System.Runtime.Serialization;
        using System.Runtime.Serialization.Formatters.Binary;

public static object CloneObject(object obj)
{
using (var memStream = new MemoryStream())
{
var binaryFormatter = new BinaryFormatter(null,
new StreamingContext(StreamingContextStates.Clone));
binaryFormatter.Serialize(memStream, obj);
memStream.Seek(0, SeekOrigin.Begin);
return binaryFormatter.Deserialize(memStream);
}
}
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

dullman

August 10, 2014, 12:50:58 am #23 Last Edit: August 10, 2014, 02:59:55 am by dullman
I wrote my own clone method for system class, because i tried some method with serialization and error cames that it ruby objects are not serializable.
But it's not what i wanted to ask, my question for today is how to add new key and value to hash simply accessing through array gives an error that value does not exist, also the second question is how to check if key exists in hash.

ps. sorry for asking many question but after i write editor it should be less question from my end.

EDIT : there is one thing i wanted to ask is there a good reason to keep in arrays a nil object on 0 index?? is there needed by game if yes where?? I Ask since my arrays are keep objects from index 0, so they don't have a nil object in the beginnig.

EDIT2 : i found how to set up a new value in hash (it seems that has the same methods as hastable class of c#)

ForeverZer0

Quote from: dullman on August 10, 2014, 12:50:58 am
...also the second question is how to check if key exists in hash.


If I remember correctly, you can use a hash exactly the same as C# Dictionary<object, object>, since that is the actual underlying type being used. I am pretty sure methods like "hash.ContainsKey(keyName)" work.

Quote from: dullman on August 10, 2014, 12:50:58 am
ps. sorry for asking many question but after i write editor it should be less question from my end.


It's not a problem, that's what this section of the forum is for.

Quote from: dullman on August 10, 2014, 12:50:58 am
EDIT : there is one thing i wanted to ask is there a good reason to keep in arrays a nil object on 0 index?? is there needed by game if yes where?? I Ask since my arrays are keep objects from index 0, so they don't have a nil object in the beginnig.


Yes, to be compatible with RMXP, you need null at the beginning. It's annoying always having to check if an element is not null when using "foreach" iterators, but that's the way Enterbrain designed it. It's simply so that all the database items "id" property match up o the corresponding array index.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

dullman

QuoteYes, to be compatible with RMXP, you need null at the beginning. It's annoying always having to check if an element is not null when using "foreach" iterators, but that's the way Enterbrain designed it. It's simply so that all the database items "id" property match up o the corresponding array index.

I think I let myself to rewrite this and use objects that doesn't nil in the beginning at least for all class I will rewrite, like animation class I believe that don't need to be changed (at least now in the beginning of writing my own game, in the future maybe it will be changed)

ForeverZer0

Compatibility is not something to take lightly, and "re-writing" the core classes is not a good idea at all if you want someone to ever actually use this. You basically are making it incompatible with the majority of existing scripts out there, just because you don't want to have to check if an item is null inside a loop. It's really not that difficult to do or work with.

			// With a "for" loop
for (var id = 1; id < actors.size; id++)
{
// Do stuff with actors
}

// With a "foreach" loop
foreach (dynamic actor in actors)
{
if (actor == null)
continue;
// Do stuff with actors
}


And if that is too difficult, you could always just write up a quick custom enumerator.

It's going to be especially horrible if you decide to have some use a 0 index, while others use a starting index of 1. That's just plain old bad programming. It's your project, and you do with it what you please, but I am just giving you a little insight from experience and knowledge I have gained: If you decide to take this route, my opinion is your project is going to fail.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

dullman

Quote from: ForeverZer0 on August 10, 2014, 08:01:49 am
Compatibility is not something to take lightly, and "re-writing" the core classes is not a good idea at all if you want someone to ever actually use this. You basically are making it incompatible with the majority of existing scripts out there, just because you don't want to have to check if an item is null inside a loop. It's really not that difficult to do or work with.

			// With a "for" loop
for (var id = 1; id < actors.size; id++)
{
// Do stuff with actors
}

// With a "foreach" loop
foreach (dynamic actor in actors)
{
if (actor == null)
continue;
// Do stuff with actors
}


And if that is too difficult, you could always just write up a quick custom enumerator.

It's going to be especially horrible if you decide to have some use a 0 index, while others use a starting index of 1. That's just plain old bad programming. It's your project, and you do with it what you please, but I am just giving you a little insight from experience and knowledge I have gained: If you decide to take this route, my opinion is your project is going to fail.


I know it's some bad programming but i'm too lazy to rewrite entire rpg maker engine (i waited few years to arc engine to be completed :) ). Also here the difference that will make my own classes unique and probably increase resources requirements, the RPG keep objects static in $data arrays, all other object keep their id as identifier whilst my modified class will keep an instance of object and to identify object use their name (like class name, also it the reason i use hash for stats since i want in the middle of development add freely new stat, class etc.), the id property i keep only for compatibility with RPG standard classes and editor. The only modified class by me that will be kept and used like standard RPG Maker is Skill class but it because i didn't want to rewrite Blizz-Abs script (i believe it should have some AI o decide if enemy|actor use skill in battle and since battle systems are the only systems that i failed to create)

ForeverZer0

What you are saying does not make sense. You cannot remove the nil value at the beginning of the data array, and somehoe expect that the array can still be referenced the same by RMXP and other scripts. You say that you are not rewriting the engine, but your removing the nil element is going to require you do that. Sure, your project might be able to find the correct item if its comparing the class, but nothing else in the engine or scripts does that, so their screwed.

If all you are trying to do is dynamically add new stats, you are going completely the wrong way about doing it. Google "Ruby meta-programming". Ruby is dynamic, you can build new classes and methods dynamically at run-time without totally throwing compatibility out the window. Your classes are going to be unique in the regard that they cannot work with anything other than your project.

What exactly are you trying to re-write here? Are you talking about re-writing the RPG module and classes, and basically a new editor for the database?
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

dullman

Basically yes i'm talking about rewriting many of base class from RPG Module so is that why i need an editor, I know that i need to rewrite many scripts but it will be done, the only what i can't do is to write my own BattleSystem (although i use a few scripts that i made compatible with my changes like your CMS), the only i can is minor fixes to that so basically i left BS as i received from forum (i rewrited damage, maxhp, hit tests to fit my idea what ideal battle should look like ( i like games based on DnD rules so it will pretty similar)). E.g For classes i added few improvements (for now i see in future that will add more when i have a basic editor completed), half properties i keep only for compatibility with RPGMaker editor(but it also could be removed since my game will not use them at all - I will remove all references to them), and other half i will use in game. The new properties i added to class is e.g. type_of_weapons that class can use so if weapon tags include tag from type_of_weapons the actor can use a weapon.

ps. I will basically re-write many of RPG modules, some fixes to BlizzAbs, Add Many new function since game will be basically a sim game with rpg elements, Many of Windows because i want the main controller of game will be mouse (Although i'm pretty satisfied how your CMS work with mouse_controller from blizzard), Scenes since base res will be 1024x768, and also add many new scenes to make possible to manage sim character of game, after i complete editor i will search for script that enlarge tiles to make it compatible with sprites about 120 pixels height, and might change sprite class to support more than four frames in sprites (since i want an animation of every work for every sprite), Many Game classes will be also rewrote to fit them to sim character of my game, basically i rewrite everything besides maps and classes that are bound with Map and Graphics (besides res script). Since From the beginning i wanted to use Xna and C# to make my own engine, but to lazy to write editor with maps so i decided to go with rpg maker.

ForeverZer0

Sound like the editor is as big as project as a the game itself. If this for a game you yourself are creating, why even make an editor? Everything you just said is easier to just script it.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

dullman

In the game that i'm in team (at least was) we have currently 400+ actors, all include in the script is pain to ass.

Also second argument i want to be able easy adjustment to their strength, traits (add or remove depends on if it fits to character).

Third argument after i'm making a tech demo i will go crowdfunding to find money to pay for spriters to make custom animation (if i will have enough also custom tilesets, and everything else that i might need to game, Also i know that first i need to ask authors of script if I can use in semi-commercial project like that, although the game will be free, the same with source code i plan to release dlc to game with new class, actors etc. depends on the money i gained through crowdfunding). Also i want find some team members who will share their vision of game with me, help me with base project, write events, add new ideas (like classes, jobs, traits or even stats) so i want to have a tool that they could work on game along with me.

Fourth argument i want the game to be easy moddable, so everyone interested can add to game their own events, actors, class and much more.

Fifth argument i don't like keep information of objects in scripts, it not easy moddable and everytime i want to change value i need to open RPG Maker XP or Gemini.

I know it will be many work in this game so i give myself a few years to complete project but when i have time and will i will work during free time on it.
Also i want to see more games that are using many custom scripts, so i have a hope that i inspire someone to make new game (although only in xp because i hate chibi sprites in VX and Ace)

ForeverZer0

I don't know, my opinion is unchanged, still easier to script, you have to open an editor either way. I don't mean to turn you off to the idea, I have created many things that are actually unnecessary just to have fun creating it, so I understand that completely.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

dullman

Quote from: ForeverZer0 on August 10, 2014, 11:05:22 am
I don't know, my opinion is unchanged, still easier to script, you have to open an editor either way. I don't mean to turn you off to the idea, I have created many things that are actually unnecessary just to have fun creating it, so I understand that completely.


Every one has their opinion i like to keep all base information in separate files or objects, but your approach to keep all in scripts have also some pros, first and mos important all changes are compatible with saves, on other hand i prefer decreased time in creating new actor, class etc when i would have an editor.

Also as the this part is used to ask question i have another:
what i want to is to add a value to database, and also modifying existing scripts in rpg maker, so i have a condition name for adding bonus to actors, when i add to DB in editor i want to add in four places information about that: three are methods get_bonus(value = 0) in trait, base_item and state class and one is a const in module that keep information regarding how const is named in hash with bonuses. So my question is how to access script data, and if there a function that after accessing i can find a chosen fragment of texts (like regexp for ironruby or find option).

ForeverZer0

This is what I meant when you need to understand the data structure of RMXP very well before doing this. This is why I included the Zlib methods in the Ruby class I showed you.

var scripts = Ruby.MarshalLoad(@"Data\Scripts.rxdata");

foreach (var script in scripts)
{
    var id = script[0]; // Unique ID assigned to every script
    var title = script[1].ToString(); // Script title
    var compressedText = script[2]; // IronRuby.MuteableString compressed with Zlib
    var text = Ruby.ZlibInflate(compressedText); // This is your script text as a System.String
}


I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

dullman

I need a help with editor, what i want is to add item to loot but to do that in proper way i need to find if item is Weapon, Armor Or Item class, if i getType() it returns RubyObject, so is there any way to check in c# what type of ruby object is it??

G_G

Do your eval function.

var isItem = Ruby.Eval("item.is_a?(RPG::Item)");