Jump to content


Photo

INSTANCE CREATION CODE


  • Please log in to reply
3 replies to this topic

#1 gameside

gameside

    GMC Member

  • GMC Member
  • 70 posts

Posted 25 February 2012 - 12:13 PM

hi there!
i made a check box using sprite for enable\disable [username] and [password] and i used one object for multiple instance in the room
it enter data in registry
1)username
2)password
i want when i check it it must enter value (1) and again if i unchecked it enter value(0)
here is the code i used for chick box

:GM023:
//create event
value="0"
chk_box =0

:GM126:
//step event
if chk_box =0{
image_index=0
}
else
if chk_box =1{
image_index=1
}

:GM129:
//left mouse press event
if chk_box =0{
chk_box=1
value="1"
}
else
if chk_box =1{
chk_box=0
value="0"
}

execute_string(reg)

in room object creation code for instance [username]

//creation code for username
reg=registry_set_root(0)
reg=registry_write_string_ext("Software\game\","Username",value)

and in room object creation code for instance [password]

//creation code for password
reg=registry_set_root(0)
reg=registry_write_string_ext("Software\game\","Password",value)

but the problem is when i run it show an error :GM071:

___________________________________________
EXECUTION ERROR in creation code for instance 100180 in room test
Error in code at line 3:
reg=registry_write_string_ext("Software\game\","Username",value)
^
at position 60: Unknown variable value

please help me!

Edited by gameside, 25 February 2012 - 12:19 PM.

  • 0

#2 AhmedElyamani

AhmedElyamani

    Yamani

  • Validating
  • 1569 posts
  • Version:GM:Studio

Posted 25 February 2012 - 12:22 PM

if the objects are two different objects you should write the object name before the variable like this : obj_checkbox.value

#3 gameside

gameside

    GMC Member

  • GMC Member
  • 70 posts

Posted 25 February 2012 - 03:04 PM

if the objects are two different objects you should write the object name before the variable like this : obj_checkbox.value


i did that before but still error :GM071: please help me :sad:
I really aprecciate any help.
  • 0

#4 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 27 February 2012 - 05:32 AM

You're using execute_string wrong.

//creation code for username
reg=registry_set_root(0)
reg=registry_write_string_ext("Software\game\","Username",value)

That doesn't store the code itself as you think. It executes registry_set_root and registry_write_string_ext immediately, and (provided that it runs without error) merely sets the value read from the registry, either "0" or "1", to the variable.

execute_string(reg)

So, this part will only do either execute_string("0") or execute_string("1").

What you need to is to set the key name in each instance's creation code:
//creation code for username
key = "Username";
//creation code for password
key = "Password";
Then use those keys whey you need to read or write registry.
//left mouse press event
chk_box = !chk_box; // Turn it to 0 when it is 1 or vice versa.
value = string(chk_box); // Turn it into a string
// Then write the registry
registry_write_string(key, value);
By the way, it is advised just to use registry_write_string (without _ext) in this case, so Game Maker will automatically allocate the appropriate key for your game that won't interfere with other software. Indeed, the "ext" version should only be used when you definitely need to read and write outside standard locations and UNDERSTAND what you're doing.

For the future reference, your code has a many room for optimization. For instance, this part:

if chk_box =0{
image_index=0
}
else
if chk_box =1{
image_index=1
}

Can be reduced into this.
image_index = chk_box;
And there is no need to bother converting a value to string. You can write it as a number at the first place.
registry_write_real(key, chk_box);

Edited by torigara, 27 February 2012 - 12:08 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users