Author Topic: A Question Of Data(  (Read 6597 times)

0 Members and 1 Guest are viewing this topic.

Offline Elsewhere

  • LV2 Member (Next: 40)
  • **
  • Posts: 26
  • Rating: +5/-1
    • View Profile
A Question Of Data(
« on: February 10, 2011, 06:18:26 pm »
So, first off, I'd like to say hello all, as this is my first post here.

Anyway, getting to the matter at hand, and I don't know if this is the right place, I have a question about how I should properly use the Data( command.

I have a variable in my program, let's call it A, and I do
Code: [Select]
:Data(1,0,1,0,0,0,0,0,0,1,0,1)->Ato write to it. I then read from it like so:
Code: [Select]
:If {B+A}=0
:(stuff)
:Else
:(other stuff)
:End
where B is added to get me the value stored in the Bth position after A.

This all works very well, just as I'd expect it to, but the problem arises when I try to assign different values to A using Data(. Throughout the course of a level in the game, all the values in A are set to 1. The problem I'm experiencing currently is that using Data( again to just rewrite to A doesn't work and re-entering the level after completion (without actually ending and re-executing the game, mind you) has all those values still set to 1. I've tried DelVar, storing 0 to the first place then Fill( -ing, using the same method I used to write to it (0->{B+A}) and just more Data(, but it seems I don't have an appropriate grasp on what I'm doing because all the values in A remain at 1 after being set once. I can't tell if I'm performing these actions wrong or it doesn't work, so I'm wondering if any of you gurus out there know how to rewrite a list of data to a variable. And also, is Data( even supposed to be used on variables, or am I writing onto the first byte which is the variable and then into the positions onward, which are not meant for the variable?

The source is really big, messy, and hard to sift through so I won't include it unless someone thinks it'll help. :-X

Ashbad

  • Guest
Re: A Question Of Data(
« Reply #1 on: February 10, 2011, 06:30:22 pm »
well, can you show how you reassign the values?  there's certain ways of treating it that will not work.

Offline NinjaKnight

  • LV2 Member (Next: 40)
  • **
  • Posts: 20
  • Rating: +2/-0
  • Hey! Look behind you! It's a -- (runs)
    • View Profile
Re: A Question Of Data(
« Reply #2 on: February 10, 2011, 06:40:26 pm »
Well, Data( includes the data in your program. This would be self-modifying code, which can get messy. If it's an application, this will most certainly not work, as SMC and apps do not mix.

If you're using it to store level data, why not just make a temporary appvar, copy the level to that, and mess around with it there?
Ninja vs. Chuck Norris == n/0. Both end with the world blowing up.

"We could use up two eternities in learning all that is to be learned about our own world and the thousands of nations that have arisen and flourished and vanished from it. Mathematics alone would occupy me eight million years."
-Mark Twain

Ashbad

  • Guest
Re: A Question Of Data(
« Reply #3 on: February 10, 2011, 06:42:08 pm »
that's could be nice, but for 10 bytes?  I would say go with SMC for now, if you have a small program.  SMC is quite useful, but only on one run (or if you inline an assembly opcode).  Otherwise do what he says.

But can you post what you're doing with your data?

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: A Question Of Data(
« Reply #4 on: February 10, 2011, 06:46:52 pm »
So, first off, I'd like to say hello all, as this is my first post here.

Anyway, getting to the matter at hand, and I don't know if this is the right place, I have a question about how I should properly use the Data( command.

I have a variable in my program, let's call it A, and I do
Code: [Select]
:Data(1,0,1,0,0,0,0,0,0,1,0,1)->Ato write to it. I then read from it like so:
Code: [Select]
:If {B+A}=0
:(stuff)
:Else
:(other stuff)
:End
where B is added to get me the value stored in the Bth position after A.

This all works very well, just as I'd expect it to, but the problem arises when I try to assign different values to A using Data(. Throughout the course of a level in the game, all the values in A are set to 1. The problem I'm experiencing currently is that using Data( again to just rewrite to A doesn't work and re-entering the level after completion (without actually ending and re-executing the game, mind you) has all those values still set to 1. I've tried DelVar, storing 0 to the first place then Fill( -ing, using the same method I used to write to it (0->{B+A}) and just more Data(, but it seems I don't have an appropriate grasp on what I'm doing because all the values in A remain at 1 after being set once. I can't tell if I'm performing these actions wrong or it doesn't work, so I'm wondering if any of you gurus out there know how to rewrite a list of data to a variable. And also, is Data( even supposed to be used on variables, or am I writing onto the first byte which is the variable and then into the positions onward, which are not meant for the variable?

The source is really big, messy, and hard to sift through so I won't include it unless someone thinks it'll help. :-X

If you want to manipulate the data, I suggest you don't use the data command.
Try this where ? = the number in the list of data.

:? -> {L1}
:? -> {L1+1}
:? -> {L1+2}
:? -> {L1+3}
and so on.



« Last Edit: February 10, 2011, 06:47:26 pm by Happybobjr »
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline Elsewhere

  • LV2 Member (Next: 40)
  • **
  • Posts: 26
  • Rating: +5/-1
    • View Profile
Re: A Question Of Data(
« Reply #5 on: February 10, 2011, 08:42:08 pm »
Happybobjr: I think that'd work but it would be a pain because I have to generate levels using this procedure and all that storing would take forever. I guess if there was no other way, I could do that.

Ashbad: I change individual values using #->{B+A}, and when (attempting to) recreate the level, I use Data( the same way I did it when I initialized it.

Interestingly enough, if I beat a level and try another one, the Data( command works and the level acts like normal until I beat it, at which point it also is already finished upon re-entry. Ending the program and re-starting it makes everything work again (albeit just once, as before).

Anyway, enough beating around the bush. Here are the related lines:
(L is the level. W is the variable I'm using Data( on to generate parts of the level. X and Y are the width and height respectively of a specific level.)
Code: [Select]
:0->W
:Data(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)->W
:If L=0
:6->X:3->Y
:Data(0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,0)->W
:.The length of this is equal to X*Y, as that's the number of positions in the room
:End
:If L=1
:.Other level stuff, all in the same format as the first.
Code: [Select]
:For (Z,0,(X*Y))
:If {Z+W}=1
:.Draw the "on" sprite
:Else
:.Draw the "off" sprite
:End
Code: [Select]
:For (Z,0,(X*Y))
:If {Z+W}=1
:0->{Z+W}
:End
:End
Cut out a lot in that last one, and some in the others, but that's the general format of my creating, reading, and writing. I don't know if that works or not but it seems to because it modifies what's drawn in the correct space in the drawing label. When attempting to rewrite the variable to something entirely different, the first label is executed, making it the same as when the values were initialized, but all the values in A stay at 1 for some reason.
« Last Edit: February 10, 2011, 08:45:15 pm by Elsewhere »

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: A Question Of Data(
« Reply #6 on: February 10, 2011, 09:08:45 pm »
I believe what you want to do is copy the data to another spot so you can mess with it and still have your original data safe and still intact. :)  For this, you'd want to use the Copy() command to copy the data into SafeRAM (may I suggest L1), and then instead of referencing the data with 'A', reference it with 'L1'. :)  I hope I understood you correctly. :D  Good luck!

Offline Elsewhere

  • LV2 Member (Next: 40)
  • **
  • Posts: 26
  • Rating: +5/-1
    • View Profile
Re: A Question Of Data(
« Reply #7 on: February 10, 2011, 09:18:58 pm »
Wow, that worked beautifully! I don't know why (probably had to do with the differences between the "List" variables and the usual ones) but it did. Thanks, everybody!
« Last Edit: February 10, 2011, 09:19:26 pm by Elsewhere »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: A Question Of Data(
« Reply #8 on: February 11, 2011, 12:33:19 pm »
Hmmm interestingly enough, to me it looks like what you were doing had sound logic and should have worked.  Probably some quirk somewhere messing with us... well glad you got it to work :)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: A Question Of Data(
« Reply #9 on: February 11, 2011, 07:32:37 pm »
It's because Data() defines the data at compile time, so no data copying is done at runtime. Therefore if you modify a Data() block, it stays modified even if the "store" statement is run again (because all that's being stored is a pointer to it)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman